fix: keep file panel animation smooth by caching the highlight tree - #653
Open
ping1999 wants to merge 1 commit into
Open
fix: keep file panel animation smooth by caching the highlight tree#653ping1999 wants to merge 1 commit into
ping1999 wants to merge 1 commit into
Conversation
Panel open/close and text selection re-rendered FileViewer, and react-syntax-highlighter rebuilt every token element on each render (~500 ms long tasks on a 668-line file). Cache the syntax and lightweight source trees with useMemo and skip no-op selection range updates; open/close and drag-select now run at full frame rate with zero long tasks.
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
Caches the rendered syntax-highlight tree and the lightweight source-line list in
FileViewerwithuseMemo, so unrelated re-renders no longer rebuild every token element. This removes the multi-hundred-millisecond long task that previously made the file panel's open/close animation stutter and made text selection feel laggy.Behavior
Verification
tsc --noEmitnpm run lint -- --quietnpm test)Recording
https://github.com/user-attachments/assets/6f17756c-c50f-440b-a7b3-f36966870742
https://github.com/user-attachments/assets/f9fb20e0-3b50-4631-9d42-f3bed2d84d21