-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Block Bindings: avoid using local state for bound attributes #60276
Conversation
Size Change: -5 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
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. |
After talking in a Slack conversation, we considered using the block attributes to store the bound values could bring some issues. Using a local state to store the data from the external source is okay. |
What?
This pull request removes the local state that stores the bound attribute values and instead relies on the block attributes object, like a regular block.
The changes to the bound attribute values are made non-persistent, to avoid adding undesired events in the editor history.
Additionally, it fixes an issue with the use of the MarkPersistent() RichText hook (props to @michalczaplinski)
Why?
Because creating an instance of a local state can negatively impact the implementation's efficiency in terms of resources, no matter how small. Additionally, it makes the implementation more unnecessarily complex.
How?
Taking advantage of the
syncDerivedUpdates()
action, and fixing the MarkPersistent() issue.Testing Instructions
Testing Instructions for Keyboard
core/paragraph
core/image
Screenshots or screencast
Screen.Recording.2024-03-28.at.10.58.39.mov