fix: tag tree virtualizer re-measure and scroll-to-selected#179
Open
bk-ty wants to merge 1 commit intokenforthewin:mainfrom
Open
fix: tag tree virtualizer re-measure and scroll-to-selected#179bk-ty wants to merge 1 commit intokenforthewin:mainfrom
bk-ty wants to merge 1 commit intokenforthewin:mainfrom
Conversation
Two issues with the tag tree virtualizer after expand/collapse: 1. Expand/collapse changed flatTags length but the virtualizer did not remeasure, causing the scroll area to show the wrong total height until the next unrelated re-render. Added a useEffect on flatTags and virtualizer that calls virtualizer.measure() when the tree structure changes. 2. The scroll-to-selected effect read tagIndexMap via the closure's stale capture rather than the latest value at fire time, so the first render after a tag became selected would scroll to index 0 instead of the target tag. Added tagIndexMapRef (updated on every render) so the effect always reads the current map without needing tagIndexMap as a dependency (which would create spurious re-fires).
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.
Problem
Two related issues with the
TagTreevirtualizer after expand/collapse:1. Stale height after expand/collapse
Expanding or collapsing a tag node changed
flatTagslength, but the virtualizer did not remeasure. The scroll area reported the wrong total height until an unrelated re-render happened to trigger a measure, causing visible layout jumps.2. Scroll-to-selected uses stale tagIndexMap
The scroll effect captured
tagIndexMapat mount time. When a tag was first selected, the effect fired with the initial (often incomplete) map rather than the current one, scrolling to index 0 instead of the correct target.Fix
useEffecton[flatTags, virtualizer]that callsvirtualizer.measure()whenever the tree structure changestagIndexMapRef— updated on every render outside any effect — so the scroll effect always reads the current map without needingtagIndexMapas a dependency (which would create spurious re-fires on every map mutation)Testing
npx tsc --noEmit— clean