-
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
useBlockSync: Fix race condition when onChange callback changes #24012
useBlockSync: Fix race condition when onChange callback changes #24012
Conversation
Size Change: +13 B (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
packages/block-editor/src/components/provider/test/use-block-sync.js
Outdated
Show resolved
Hide resolved
😬 ayy sorry for the miss. |
881c7c2
to
a530aaf
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.
Awesome! I can confirm this fixes #23967. The changes make sense to me, onChange/onInput should no longer become outdated in the subscribed function using these refs. And thank you for adding the test! 😄
(small nit Q on the test but this looks good!)
* Fix race condition when onChange callback changed * Add tests to cover the scenario
Description
In the
useBlockSync
hook, if theonChange
oronInput
callbacks changed while the same component instance was being used, the oldonChange
/onInput
callbacks were used instead of the updated ones.For more context, in #23292, we started setting a ref with the latest onChange/onInput callbacks, but we unfortunately never consumed that ref. cc @youknowriad. This updates the block-editor subscription such that it uses the
onChange
andonInput
refs. This way, it always uses the latest versions of the callbacks.Specifically, this fixes #23967 (a result of the race condition).
How has this been tested?
Locally, in edit-site.
Screenshots
Before:
After:
Types of changes
Bug fix.
Checklist: