fix(knowledge): preserve scroll position when toggling tokenizer in chunk viewer#4643
fix(knowledge): preserve scroll position when toggling tokenizer in chunk viewer#4643waleedlatif1 wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview The toggle now captures the active element’s Reviewed by Cursor Bugbot for commit 0e1e331. Configure here. |
Greptile SummaryThis PR fixes a UX bug where toggling the Tokenizer switch in the Knowledge Base chunk viewer would reset the scroll position to the top. The fix captures
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to scroll-position bookkeeping in a single UI component with no side effects on data, saving, or network calls. The fix is small and self-contained: two new refs, one new callback, and one layout effect. The hasToggledTokenizerRef guard correctly prevents the effect from running on initial mount, the scroll capture happens synchronously before state update, and useLayoutEffect restores it before the browser paints, so there is no visible flicker. No data paths, API calls, or shared state are touched. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant TokenizerToggle
participant handleTokenizerChange
participant preservedScrollTopRef
participant React State
participant useLayoutEffect
participant DOM
User->>TokenizerToggle: clicks toggle
TokenizerToggle->>handleTokenizerChange: onCheckedChange(newValue)
handleTokenizerChange->>DOM: read scrollTop from active element
handleTokenizerChange->>preservedScrollTopRef: store scrollTop
handleTokenizerChange->>React State: setTokenizerOn(newValue)
React State->>DOM: unmount old element, mount new element
DOM->>useLayoutEffect: fires synchronously (before paint)
useLayoutEffect->>preservedScrollTopRef: read stored scrollTop
useLayoutEffect->>DOM: set scrollTop on newly-mounted element
DOM->>User: renders at preserved scroll position
Reviews (2): Last reviewed commit: "fix(knowledge): skip scroll restore on i..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0e1e331. Configure here.
Summary
scrollTopfrom the active element (textarea or tokenized div) before the toggle, then restores it on the newly-mounted element viauseLayoutEffectType of Change
Testing
Tested manually
Checklist