Skip to content

Fix notebook scroll tracking after source recovery - #35034

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/notebook-scroll-recovery
Oct 29, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/notebook-scroll-recovery

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 0

Problem

useIpynbScrollRestoration attached its scroll listener only when rootRef/scrollCacheKey changed. When a .ipynb opens with invalid JSON (e.g. merge-conflict markers or a partial write), IpynbViewer renders the error panel without the notebook root, so the listener effect runs with no element. After the file is repaired externally, the root mounts but the effect never re-runs, so scroll is never cached and switching tabs and back resets the notebook to the top.

Separately, the restore effect depended on raw content. The cache is written 150 ms after scrolling stops, so a content republish during scrolling (kernel output updates, source-draft commits) snapped the view back to the stale cached position.

Fix

Pass notebook readiness (parsed.notebook !== null) instead of content, and depend on it in both layout effects. The listener attaches when the notebook root first appears after recovery, cleanup detaches it when the notebook becomes invalid, and restore runs on mount/readiness changes instead of on every content change.

Test

  • useIpynbScrollRestoration.test.tsx: invalid → valid without remounting tracks and restores scroll (fails on main).
  • pnpm check:changed --maxWorkers=2 passes.

@OrcaWin
OrcaWin force-pushed the OrcaWin/notebook-scroll-recovery branch from 15289e7 to d27e0e9 Compare October 28, 2026 23:15
@OrcaWin
OrcaWin marked this pull request as ready for review October 29, 2026 00:08
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cd0dc2c8-4843-403e-8345-84da447a59dd
Commits

Reviewing files that changed from the base of the PR and between b2feed0 and 77b34f8.

Files selected for processing: 3
  • src/renderer/src/components/editor/IpynbViewer.tsx
  • src/renderer/src/components/editor/useIpynbScrollRestoration.test.tsx
  • src/renderer/src/components/editor/useIpynbScrollRestoration.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the remaining test suggestion is non-blocking.

Findings

  1. P2 Scroll-jump fix remains untested ▶

Summary

This PR fixes notebook scroll tracking after invalid source is repaired.

  • Notebook scroll tracking follows whether the file can be read.

Reviews (2) · Last reviewed commit: "Fix notebook scroll tracking after sourc..." · Reviewed by Greptile

Comment on lines +26 to +33
it('remembers scroll when invalid source becomes a notebook without remounting the viewer', () => {
const view = render(<NotebookScrollSurface ready={false} />)
view.rerender(<NotebookScrollSurface ready />)
const notebook = screen.getByTestId('notebook')
notebook.scrollTop = 500
fireEvent.scroll(notebook)
vi.advanceTimersByTime(150)
expect(scrollTopCache.get('notebook')).toBe(500)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Scroll-jump fix remains untested

The new test covers recovery, but not the separate fix for content updates during scrolling. Add a test that scrolls, republishes valid notebook content before the 150 ms timer fires, and checks that the position stays unchanged. It should fail with the old content dependency; the current test cannot catch that regression.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Key the notebook scroll listener and restore effects on notebook
readiness instead of raw content, so the listener attaches once an
invalid notebook becomes valid and content republishes no longer snap
the view back to a stale cached position.
@OrcaWin
OrcaWin force-pushed the OrcaWin/notebook-scroll-recovery branch from d27e0e9 to 77b34f8 Compare October 29, 2026 00:27
@OrcaWin
OrcaWin merged commit 05c2667 into main Oct 29, 2026
35 checks passed
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