-
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
useAsyncList: flush state updates when processing queue #48238
Conversation
Size Change: +23 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
...state, | ||
...list.slice( nextIndex, nextIndex + step ), | ||
] ); | ||
} ); |
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.
While this PR restores the previous behavior (prior to the upgrade). I think it's still not perfect. Personally, I think we should be calling asyncQueue.add( {}, append( nextIndex + step ) );
outside the callback. kind of like I did here
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.
Personally, I think we should be calling
asyncQueue.add
outside the callback.
Pushed a commit that implements that 👍 Behavior-wise it's exactly the same, it just add all the work to the queue upfront, instead of adding each new task just in time right before the next iteration of the for of waitingList
loop inside priority-queue
.
Flaky tests detected in 47e7b5b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4222258567
|
Does this PR replace #48085 ? |
Yes it does 🙂 |
Here I ran an experiment where I removed |
Thank you so much for the heads up @youknowriad 🙇 ! As far as I checked, we don't use the hook |
Cherry-picked this PR to the wp/6.2 branch. |
Fixes
useAsyncList
in concurrent mode by usingReactDOM.flushSync
to synchronously run all the renders and effects triggered bysetState
. Doing the work insiderequestIdleCallback
and consuming thetimeRemaining
provided by it.Fixes the issues discussed in #48085. In that discussion, I was wrong about
flushSync
not being sync, and merely scheduling a microtask. It indeed is completely sync, doing all the rendering work and even effects synchronously. Very similar toact()
in tests in this regard.I'm wondering how this will work in React Native.
flushSync
is areact-dom
API, not available in thereact-native
package.