Repository navigation
Fix notebook scroll tracking after source recovery - #35034
Conversation
15289e7 to
d27e0e9
Compare
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
[Medium impact] The PR appears safe to merge; the remaining test suggestion is non-blocking. Findings
SummaryThis PR fixes notebook scroll tracking after invalid source is repaired.
Reviews (2) · Last reviewed commit: "Fix notebook scroll tracking after sourc..." · Reviewed by Greptile |
| 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) |
There was a problem hiding this comment.
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.
d27e0e9 to
77b34f8
Compare
Problem
useIpynbScrollRestorationattached its scroll listener only whenrootRef/scrollCacheKeychanged. When a.ipynbopens with invalid JSON (e.g. merge-conflict markers or a partial write),IpynbViewerrenders 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 ofcontent, 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=2passes.