-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix(embed-block): Only call setAttributes()
when attrs change
#68141
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Thanks for contributing, @chrisbellboy! Are you rebasing this branch on top of the last trunk? P.S. The fix looks good. |
Hi, @chrisbellboy Do you mind rebasing this on top of the latest trunk? That should resolve some CI check problems and make it easier to test manually. Thank you! |
78d824f
to
1ad0256
Compare
Hi @Mamaduka Of course, no problem, all done 👍 And apologies for not getting back to your previous message sooner! |
Thank you, @chrisbellboy! I'll try to review and test this properly ASAP. |
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 contributing, @chrisbellboy!
The fix works as expected ✅
What?
Fixes: #61778.
Prevents
setAttributes()
from being called whenever the block remounts and no attributes have changed.Why?
Due to the way
setAttributes()
currently works and how the embed block calls setAttributes() with a new shallow copy of attributes whenever the block is remounted, the following steps result in an ugly bug:This causes the full set of attributes from the last embed block selected to be set to all the other dragged embed + image blocks, changing them all into duplicate blocks of the last embed block.
The problem is due to a combination of:
setAttributes()
updates all passed attributes to all selected blocks, this was intended for mass block option editing. However, this is not always the desired behaviour.setAttributes()
using a new shallow copy of the full set of attributes.How?
The current
setAttributes()
implementation has desired and undesired effects, and needs to be expanded upon to address the undesired effects. That could indirectly fix this embed block remounting situation.However, the embed block should not be trying to update its attributes upon every block remount.
This PR Prevents the embed block from calling
setAttributes()
when no attributes have been changed.Testing Instructions
Without this PR, the image block would get turned into an embed block as its attributes are changed to be the same as the embed block attributes. Causing the image block to fail and then automatically gets converted into an embed block.