-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add widget id to blocks in the widgets screen #28379
Conversation
Size Change: -81 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall
@@ -134,13 +100,15 @@ export function createBlocksFromInnerBlocksTemplate( | |||
export function cloneBlock( block, mergeAttributes = {}, newInnerBlocks ) { | |||
const clientId = uuid(); | |||
|
|||
const sanitizedAttributes = sanitizeBlockAttributes( block.name, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of sanitize could potentially have a small performance impact (not sure if noticeable), the other thing is that it was not an expectation of cloneBock and I hope it doesn't produce unexpected side effects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does running npm run test-performance
with and without this PR demonstrate any performance regression?
...block, | ||
attributes: { | ||
...( block.attributes || {} ), | ||
__internalWidgetId: widgetId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird that we add an attribute that is not registered. I'm fine with it but I hope it's something that can break if for some reason, in the future, we apply the same "sanitizeAttributes" behavior in flows where it's not applied right now.
Let's make sure we've tests to cover this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it but I hope it's something that can break if for some reason, in the future, we apply the same "sanitizeAttributes" behavior in flows where it's not applied right now.
I'm not sure what you meant by that? What kind of tests you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not particular tests in my mind, this is meant to fix widgets updating if I'm not wrong, let's just make sure it's covered because it can easily break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e1ea247
to
46003d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
|
||
return state || {}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good riddance! ❤️
...block.attributes, | ||
...mergeAttributes, | ||
}, | ||
attributes: sanitizedAttributes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a new unit test for cloneBlock()
which tests that attributes are sanitised? (And, maybe while you're at it, double check that createBlock()
has one.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
Let's document this change of |
Description
Mentioned in this Slack thread. Basically, this PR tries to fix a saving issue in the widgets screen after merging #27885 (comment). The recap was well documented in a Slack thread comment.
The solution is to inject
__internalWidgetId
to all blocks in the widgets screen but not in their block types attributes, and modify thecloneBlock
function to only clone attributes specified inside the block types (following the same logic increateBlock
).This PR also partially reverts #28078, specifically the
__unstableCloneValue
hack.How has this been tested?
Types of changes
Breaking change
Checklist: