Repository navigation
fix(editor): extract diff first-change auto-scroll to a hook to unblock main - #21738
Conversation
DiffViewer.tsx crossed the 400-line oxlint cap (402 counted lines), so static analysis fails on main and reddens every open PR through the merge ref. Moves the self-contained "center the viewport on the first change" effect into useDiffViewerFirstChangeAutoScroll, leaving DiffViewer to own mount wiring, comment popover state, and render. No behavior change: the effect body, guards, rAF sequencing, and dependency set are carried over verbatim; diffEditorRef joins the deps as a stable ref object.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change extracts DiffViewer’s inline first-change auto-scroll effect into Priority: ⬇️ Low 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a pure code-motion refactor that extracts the diff first-change auto-scroll effect out of DiffViewer.tsx so it drops back under oxlint's 400-line cap and unblocks main.
- New
useDiffViewerFirstChangeAutoScrollhook — the inlineuseEffectand its two refs were moved verbatim intouseDiffViewerFirstChangeAutoScroll.ts; the only textual deltas are thependingScrollForThisViewer→pendingScrollCommentIdrename anddiffEditorRefjoining the dependency array (a stableuseRefidentity, so effect re-run triggers are unchanged). DiffViewer.tsxcall site — the hook is invoked at the same position as the removed effect, after the comment decorator and popover effect, preserving hook order and effect sequencing relative to the decorator's view zones. Now 390 raw lines.- No collateral cleanup needed —
useRef,useEffect, anddiffViewStateCacheare all still used elsewhere inDiffViewer.tsx, so no imports were left dangling.
I compared the removed block against the new hook body line by line and found no logic difference, confirmed no remaining references to the old inline symbols, and ran oxlint on both files (0 warnings, 0 errors — the max-lines failure is gone).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
One file in the code editor grew two lines past the size limit the project enforces. That makes the automated code check fail — not only on
main, but on every open pull request, because each one is checked against a merged copy ofmain. This moves one self-contained piece of that file into its own file. Nothing about the app changes; the size check goes green again.What Changed
src/renderer/src/components/editor/DiffViewer.tsxcounted 402 lines against a 400-line cap (blank lines and comments already excluded), sooxlintreported:The behavior that piece implements: when you open a file diff, the view scrolls so the first changed line sits in the middle of the pane instead of leaving you at the top of a long unchanged file. It has to run as its own effect rather than inside the editor's mount callback, because the inline-comment decorator inserts view zones that would otherwise push the content down after the scroll position was measured.
That whole effect — the run-once-per-file guards, the "a comment already owns this scroll" bail-out, the deferred animation frame, and the
onDidUpdateDiffsubscription — now lives inuseDiffViewerFirstChangeAutoScroll.tsand is called as a hook. The body is carried over verbatim.DiffViewer.tsxkeeps what is left: editor mount wiring, comment popover state, view-state persistence, and render.Before and after as a user experiences it: identical. Same scroll target, same timing, same render output. The only visible difference is that CI passes.
Why
Static analysis is red on
main, which makes every open PR look broken — at least #20949, #21021 and #20981 fail on exactly this error without touching the file. That hides real failures, so it is worth fixing on its own branch rather than bundling into feature work.Alternatives considered:
AGENTS.md, and it would let the file keep growing.diff-editor-hide-unchanged-options.ts); its footprint here is a single import and a single spread. There was no seam left to take.The auto-scroll effect was the right seam: one coherent responsibility, no JSX, and a direct sibling precedent in
useDiffViewerLargeDiffLifecycle.ts.Linked Issue
No tracking issue —
mainis red and this restores it.Visual Proof
N/A— pure refactor. No markup, props, render order, or styling changed; the extracted effect runs at the same point in the component with the same inputs.Testing
Run from a worktree on this branch:
npx oxlint src/renderer/src/components/editor/— clean; themax-lineserror is gone and nothing new appeared.pnpm run check:code-quality:changed— passes, 0 new findings across both changed files.pnpm test src/renderer/src/components/editor/— 1546 passed, 2 skipped, across 226 files. No test was modified.npx tsc -p config/tsconfig.web.json --noEmit— no errors incomponents/editor/. The remainingTS6307cross-project-import errors in unrelated test files are pre-existing onmain.Final counts:
DiffViewer.tsx390 raw lines (under the 400 cap for.tsx),useDiffViewerFirstChangeAutoScroll.ts86 raw lines (under the 300 cap for.ts).Tested on macOS. Platform-independent — renderer-only, no paths, shortcuts, or process spawning.
No new tests: this adds no behavior to test. The existing editor suite covers the surface and passes unchanged, which is the evidence that matters for a pure extraction.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
No impact on security, cross-platform support, SSH/remote, mobile, backwards compatibility, or performance. Renderer-only code motion within one component; the extracted hook has the same call site, inputs, and effect lifetime it had inline.
One deliberate detail for review:
diffEditorRefis now a hook argument, so it is listed in the effect's dependency array. It is auseRefobject created byDiffViewerand its identity never changes for the component's lifetime, so the effect re-runs on exactly the same triggers as before. This matchesuseDiffViewerLargeDiffLifecycle, which takes the same ref the same way.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)