Skip to content

fix: keep file panel animation smooth by caching the highlight tree - #653

Open
ping1999 wants to merge 1 commit into
agegr:mainfrom
ping1999:fix/fileviewer-highlight-memo
Open

fix: keep file panel animation smooth by caching the highlight tree#653
ping1999 wants to merge 1 commit into
agegr:mainfrom
ping1999:fix/fileviewer-highlight-memo

Conversation

@ping1999

@ping1999 ping1999 commented Aug 29, 2026

Copy link
Copy Markdown

Summary

Caches the rendered syntax-highlight tree and the lightweight source-line list in FileViewer with useMemo, 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

  • File content, language, theme, and line-wrapping still determine what is rendered; the cached trees are rebuilt whenever any of them change.
  • Highlighted and lightweight source views render exactly the same markup as before — only redundant rebuilds are skipped.
  • Selection updates during drag now skip no-op state writes: an unchanged selected line range reuses the previous state object instead of triggering a viewer-wide re-render.
  • No changes to loading, error, diff, preview, or mention-line behavior.

Verification

  • TypeScript: tsc --noEmit
  • Lint: npm run lint -- --quiet
  • Tests: 844 passed (npm test)
  • Manual profiling (668-line JS file): open/close panel animation runs at full frame rate with no long tasks (previously ~500 ms long task per re-render); drag-selecting text stays at full frame rate.

Recording

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant