Repository navigation
Conversation
This branch has not been deployed
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.
Summary
When
eachchanges but the window'sstartstays the same,VirtualRow/VirtualColumnkeeps the old window items instead of switching to the new ones. This PR rebuilds the window from the new items whenevereachchanges.Why
computeSliceonly rebuilds the window whenstartchanges (start !== prev.start || newSlice.length === 0). That's fine when items are only appended after the window, but if an item inside or before the window is reordered, removed, or replaced with a new object, the window keeps the old items.On the next key press the window shifts and is built from the new items.
<List>can't match them to the old ones, so it updates the existing nodes in place instead of sliding them over. The focused node stays where it was whileselectedmoves, and the following press puts focus in the hidden slot off-screen. This happens with or withoutwrap.Fix
In the
itemseffect, clear the window (slice.slice = noItems) before callingcomputeSlice. This takes the existingnewSlice.length === 0branch and rebuilds the window from the new items.This only runs when
eachchanges, and nothing changes in the key press path. The rebuild it triggers would otherwise happen on the next key press anyway.Tests
Added contract tests in
tests/contract-virtual.test.tsx: withscroll="always"+wrapand withscroll="auto", the focused item is moved to the front or removed, then Right is pressed twice. They check that the focused element is the child atselectedand that it shows the expected item. All 4 cases fail without the fix and pass with it, and the full suite passes.