Repository navigation
fix(hooks): resync manager after a discarded concurrent render - #2528
Closed
NerdyMihir wants to merge 1 commit into
Closed
NerdyMihir wants to merge 1 commit into
NerdyMihir wants to merge 1 commit into
Conversation
useRecyclerViewManager pushed props and data into the manager inside useMemo. A render React discards still mutates the manager, but its memo cache is dropped, so the next committed render sees unchanged deps and skips the resync. Compare against what the manager last saw instead. Fixes Shopify#2527
Author
|
Closing; leaving the fix approach described in #2527 for maintainers to take as they prefer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2527
useRecyclerViewManagercallsupdateProps(props)andprocessDataUpdate()during render insideuseMemoblocks keyed on[props]/[data]. When React discards a render (Suspense, transitions,useDeferredValue), the manager has already taken the discarded props, but the memo cache from that render is dropped. The next committed render has the same deps as the last commit, so both memos skip and the manager stays on the discarded data. With a longer discarded array, the list renders indices past the committed data:index out of bounds, not enough layoutson 2.3.3,renderItemwithitem === undefinedon 2.0.x.The fix keeps the last
props/datathe manager actually received in auseStateobject and re-syncs whenever the current render's values differ from it. Renders that commit normally behave as before: oneupdatePropsper newprops, oneprocessDataUpdateper newdata, including the first render.src/__tests__/useRecyclerViewManager.test.tsxreproduces it on a concurrentreact-test-rendererroot: a deferred 2→6 row update suspends and is discarded, then anextraDatachange re-renders. It throws onmainand passes with the fix.Reviewers’ hat-rack 🎩
yarn test --forceExit,yarn type-check,yarn lintare green locallyindex out of bounds, not enough layoutsprops(nodatachange) still callsprocessDataUpdateonly whendatachangesScreenshots or videos (if needed)
N/A (no visual change)