-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Address deprecation issues from Buttons flex layout PR. #36192
Conversation
Size Change: +2 B (0%) Total Size: 1.08 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.
Thanks for following with this @tellthemachines 👍 I've left a couple of comments.
@@ -29,6 +29,8 @@ const migrateWithLayout = ( attributes ) => { | |||
orientation: orientation || 'horizontal', | |||
}, | |||
} ); | |||
delete updatedAttributes.contentJustification; |
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 think we can simplify in the destructuring above.
`const { contentJustification, orientation, ...updatedAttributes } = attributes;
Also we might want only to add layout's justifyContent
or orientation
props only if the respective attribute exists so as to get the defaults from flex.layout
.
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.
Fixed!
@@ -57,7 +59,8 @@ const deprecated = [ | |||
}, | |||
}, | |||
}, | |||
isEligible: ( { layout } ) => ! layout, | |||
isEligible: ( { contentJustification, orientation } ) => | |||
!! contentJustification || !! orientation, |
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 still think we shouldn't have isEligible
here (also commented about the difference with social-links
).
This check is handled inside migrateWithLayout
, no? Have you run into some problems without it?
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 did try removing it, but migrateWithLayout
doesn't get called unless we have isEligible
here. And then trying to edit the layout for existing blocks has unpredictable results.
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.
This needs some investigation, but it seems this might be related to the other deprecation that uses isEligible
. For those we would still need to add the layout
prop if not exists.
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 tell me more about why we shouldn't have isEligible
here? As far as I can tell, if we don't use it, the migration won't run.
The block handbook says "A deprecation will be tried if the current state of a parsed block is invalid, or if the deprecation defines an isEligible function that returns true".
In this case, a block with contentJustification
or orientation
and a bunch of extra classnames isn't invalid; what happens when it runs through the current save function is the attributes get stripped and the classnames get added as attributes. So, if we want the migration to work (which we do, otherwise it'll be impossible to change the layout of an existing block), we have to use isEligible
. Or am I missing something here?
this might be related to the other deprecation that uses isEligible. For those we would still need to add the layout prop if not exists.
I did make sure to add migrateWithLayout
to the older deprecation too. Is that what you meant?
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.
In this case, a block with contentJustification or orientation and a bunch of extra classnames isn't invalid;
This seems to be right, yes. Deprecations can be super confusing at times 😄
this might be related to the other deprecation that uses isEligible.
I got confused whether we should add the layout
prop in the other deprecation but it seems fine, as we use the default layout
for the block.
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.
Thanks @tellthemachines ! As I said deprecations can be very confusing at time 😄
Yeah, deprecations are hard 😅 Thanks for updating the fixtures @ntsekouras ! |
e745230
to
3d9445d
Compare
* Address deprecation issues from Buttons flex layout PR. * Simplify migration logic. * update fixtures Co-authored-by: ntsekouras <[email protected]>
* Address deprecation issues from Buttons flex layout PR. * Simplify migration logic. * update fixtures Co-authored-by: ntsekouras <[email protected]>
Cherry picked into the Gutenberg 11.9 release in: 4b30711 |
Description
Addresses feedback from #35819.
Buttons deprecation is fixed so that layout attributes are only migrated if they are explicitly set.
Also removes unnecessary BlockControls from Buttons edit function.
How has this been tested?
Test by trying out different combinations of Buttons layouts, saving and refreshing to make sure they work as expected.
Test the deprecations by generating some deprecated markup in an older version of the editor, pasting it in a post and saving: the markup should be updated on save, unless there are no layout attributes, in which case nothing should change.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).