fix(file-viewer): prevent scroll jump to top during Mothership streaming#4559
Conversation
- Fix root cause: MarkdownCheckboxCtx.Provider was conditionally rendered, causing the scroll container to unmount/remount when isStreaming flipped, resetting scrollTop to 0 on every stream start - Add useScrollAnchor hook with spacer element to preserve scroll position when streamed content temporarily shrinks the scroll container - Linger active session ID on complete to prevent streamingContent→undefined flicker between consecutive tool calls on the same file - Gate upsert activation on incoming session having renderable content - Fix shouldShowStreamingFilePanel to keep panel mounted during linger - Fix use-chat post-write navigation to work with lingered completed session - Fix useAutoScroll to check proximity before pinning to bottom on stream start
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Updates file preview session state so Refines Reviewed by Cursor Bugbot for commit 791f76a. Configure here. |
Greptile SummaryThis PR fixes a scroll-jump bug in the Mothership file-viewer that occurs between consecutive streaming tool calls. The root causes were a conditionally-rendered context provider unmounting the scroll container on every stream start, and
Confidence Score: 5/5This PR is safe to merge — all changes are scoped to the file-viewer and chat scroll paths, and each fix is independently tested. The root causes are addressed at both the React tree level (unconditional MarkdownCheckboxCtx.Provider) and the state-machine level (linger preserves activeSessionId across tool-call gaps). The useScrollAnchor spacer logic is pure-function-testable and well-covered. Previously-flagged issues with linger clearance in hydrate and upsert(activate:false) were resolved before this review. No new auth, data, or API surface is touched. No files require special attention. The most complex new file is use-scroll-anchor.ts, and its pure helpers are thoroughly unit-tested. Important Files Changed
Reviews (4): Last reviewed commit: "chore(file-viewer): trim verbose inline ..." | Re-trigger Greptile |
… spacer after stream
|
@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 77f6364. Configure here.
…s, add hydrate linger tests
|
@greptile |
|
@cursor review |
Pulls the spacer-guard re-engage condition out of onScroll into an exported pure function so the false-re-engage invariant (spacer active → no re-engage) is covered by automated tests rather than relying on manual QA. Adds 8 unit tests for shouldReengage alongside the existing 15 for computeSpacerShortage.
|
@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 791f76a. Configure here.
Summary
MarkdownCheckboxCtx.Providerwas conditionally rendered around the scroll container, causing it to unmount/remount (and resetscrollTopto 0) every time streaming starteduseScrollAnchorhook with a spacer element that inflatesscrollHeightto prevent the browser from clampingscrollTopwhen streamed content temporarily shrinksactiveSessionIdoncompletesostreamingContentnever becomesundefinedbetween two consecutive Mothership tool calls on the same fileupserton the incoming session having renderable content, preventing a blank flash when a new session starts before its first chunk arrivesshouldShowStreamingFilePanelto keep the panel mounted while the lingered session is activeuse-chatpost-write navigation condition to work with lingered completed sessionsuseAutoScrollto check proximity before pinning to bottom on stream start (prevents unwanted jump-to-bottom in the chat panel)Type of Change
Testing
Tested manually — scrolled to middle of a file, asked Mothership to make multi-step edits. Scroll position preserved across tool call boundaries. Also verified single
patch, freshwrite, and cross-file edits all behave correctly.Unit tests added:
use-scroll-anchor.test.ts: 15 tests forcomputeSpacerShortagepure functionuse-file-preview-sessions.test.tsx: 7 new tests for linger, content-gate, and edge casestext-editor-state.test.ts: 5 new tests for inter-session content shrink scenarioChecklist