-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Remove useSelect subscription for data that does not need to be reactive #72849
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. |
|
Size Change: +4 B (0%) Total Size: 2.38 MB
ℹ️ View Unchanged
|
|
What’s the measured performance impact of the change proposed? You can also use a public method from the package that simplifies the usage. However this brings the risk that late source registration or deregistration from any of the plugins might not be immediately visible in UI without the re-render triggered from different reasons. Overall, the way block editor works without a central WP init action that would orchestrate all plugins like on the server makes it all very brittle, so reactivity mitigates some of the race conditions. |
It was quite minor, if any. Just something I came across while investigating any potential bottlenecks. I figured removing a subscription for every block is better than having it, if there aren't any downsides. But, if you think there's a risk of race conditions, then it's not worth it! I'll close this out then. |
What?
getAllBlockBindingsSources()was called viauseSelectwith empty dependencies inEditWithGeneratedProps, which wraps every block. This creates a new observer oncore/blocksfor every block. While the blocksStore rarely updates, it's cleaner to not need an extra observer for every block.Why?
We can get the value without needing it to be a subscription. This would only show up as a performance issue for tests that include many blocks on them.
How?
Replace the
useSelect( ( selector ) => {}, [] )which creates a subscription in favor ofconst { getAllBlockBindingsSources } = unlock( useSelect( blocksStore ) );which does not create a the subscription.Testing Instructions
There should be no changes from trunk
Testing Instructions for Keyboard
Screenshots or screencast