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.
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.
Personally, I think we should be calling
asyncQueue.addoutside 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
useAsyncListin concurrent mode by usingReactDOM.flushSyncto synchronously run all the renders and effects triggered bysetState. Doing the work insiderequestIdleCallbackand consuming thetimeRemainingprovided by it.Fixes the issues discussed in #48085. In that discussion, I was wrong about
flushSyncnot 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.
flushSyncis areact-domAPI, not available in thereact-nativepackage.