Repository navigation
fix(combined-diff): resolve React Doctor findings - #17506
AmethystLiang wants to merge 1 commit into
Conversation
Greptile SummaryThis PR removes React Doctor suppressions and restructures combined-diff rendering, preference derivation, ref synchronization, filtering, revalidation, localization, and scroll persistence while intending to preserve existing behavior.
Confidence Score: 4/5The PR should not merge until scroll cleanup preserves the latest user position instead of replacing it with a stale mount-time anchor. A normal scroll followed by a tab or worktree switch can persist an older anchor, causing the combined diff to reopen at the wrong position. Files Needing Attention: src/renderer/src/components/editor/combined-diff/scroll-viewport/use-combined-diff-scroll-persistence.ts
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/editor/combined-diff/scroll-viewport/use-combined-diff-scroll-persistence.ts | Capturing the DOM anchor at effect setup causes cleanup to overwrite a newer user-scroll anchor before persistence. |
| src/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsx | Extracts presentation and relocates loaded-section Git-status revalidation without another concrete defect identified. |
| src/renderer/src/components/editor/combined-diff/combined-diff-viewer-content.tsx | Preserves the prior combined-diff toolbar, tree, section-list, empty-state, conflict, and notes-dialog composition. |
| src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-view-preferences.ts | Replaces synchronization effects with derived values and explicit overrides; investigated preference flows retain reachable persistence. |
| src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-filter.ts | Uses an escaped, byte-bounded literal RegExp equivalent to substring filtering, with no supported ReDoS path. |
| src/renderer/src/components/editor/combined-diff/load-sections/combined-diff-section-load-registry.ts | Moves scheduler initialization and mutable section synchronization away from render-time ref assignments. |
Sequence Diagram
sequenceDiagram
participant U as User
participant V as Combined diff viewer
participant P as Scroll persistence
participant C as View-state cache
U->>V: Scroll to a new position
V->>P: Record fresh virtual anchor
U->>V: Switch tab or worktree
V->>P: Run layout-effect cleanup
P->>P: Replace fresh anchor with mount-time DOM anchor
P->>C: Persist stale anchor
U->>V: Reopen combined diff
C-->>V: Restore stale position
Reviews (1): Last reviewed commit: "fix(combined-diff): resolve static analy..." | Re-trigger Greptile
📝 WalkthroughWalkthroughThe combined-diff viewer now delegates rendering to Merge Risk: 🔵 Low · up to The PR refactors combined-diff loading and view restoration while preserving existing behavior. It is mergeable with explicit owner follow-up because a status change may reload more sections than necessary, section state may briefly lag during rendering, and tab switches may restore an outdated scroll position. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides a useful summary and validation results, but it omits most required template sections, including ELI5, What Changed, Why, Visual Proof, Testing details, AI Disclosure, Review, Notes, and the required checklist. Resolution Complete the missing template sections. Add the required linked issue format, provide visual proof or write N/A with a reason, document manual and automated testing with tested platforms, complete the applicable checklists, and include the required compatibility and review notes. Full details: Docstring CoverageExplanation Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 14 files. (5 skipped: 5 unsupported.)
✨ 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.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d903f5ff-13c1-4839-a9bc-65680cea36d2
📒 Files selected for processing (20)
config/scripts/check-changed-code-quality.mjspackage.jsonsrc/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsxsrc/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-filter.tssrc/renderer/src/components/editor/combined-diff/browse-files/use-combined-diff-tree-navigation.tssrc/renderer/src/components/editor/combined-diff/combined-diff-viewer-content.tsxsrc/renderer/src/components/editor/combined-diff/load-sections/combined-diff-section-load-registry.tssrc/renderer/src/components/editor/combined-diff/load-sections/use-combined-diff-section-revalidation.tssrc/renderer/src/components/editor/combined-diff/remember-view/use-combined-diff-view-restore.tssrc/renderer/src/components/editor/combined-diff/review-controls/combined-diff-toolbar.tsxsrc/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-notes-actions.tssrc/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.tssrc/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-view-preferences.tssrc/renderer/src/components/editor/combined-diff/scroll-viewport/combined-diff-section-list.tsxsrc/renderer/src/components/editor/combined-diff/scroll-viewport/use-combined-diff-scroll-persistence.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.json
💤 Files with no reviewable changes (1)
- package.json
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Important
The no-derived-state-effect fix changed how the toolbar preferences are consumed: sideBySide and fileTreeCollapsed now read the module-level combinedDiffViewPreferences singleton on every render, so a toggle in one open combined-diff pane leaks into other open panes on their next re-render. The PR's stated goal is to preserve existing behavior — see the inline comment for the fix options.
Reviewed changes
- Removed React Doctor suppressions — dropped the
reactDoctorignore overrides frompackage.jsonand theSUPPRESSED_REACT_DOCTOR_DIAGNOSTICSfilter from the changed-code-quality script. - Fixed
no-ref-current-in-render— moved render-phaseref.currentwrites intouseLayoutEffectin the load registry, tree navigation, and section actions hooks. - Replaced derived state with render-time derivation —
sideBySide/fileTreeCollapsednow derive from override state plus the module preference instead of seededuseState+ syncing effects. - Extracted
CombinedDiffViewerContent— moved the JSX body into its own component and collapsed the section list's three mode booleans into a singlemodeprop derived fromtreeMode. - Relocated the git-status reload effect from
useCombinedDiffSectionRevalidationintoCombinedDiffViewer(behavior-equivalent). - Applied CodeRabbit feedback —
toSortedinstead of copy+sort, a semantic localization key, and capturing the DOM scroll anchor ref once at effect setup.
ℹ️ Nitpicks
- The old localization key
45cf23b418was left in all five locale files after the rename tofailedToClearNotes. It is now an orphan (harmless — the extraction check only reports orphans) but can be removed for cleanliness.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| const sideBySide = | ||
| sideBySideOverride ?? | ||
| combinedDiffViewPreferences.sideBySide ?? | ||
| diffDefaultView === 'side-by-side' |
There was a problem hiding this comment.
Reading the module-level combinedDiffViewPreferences here turns a mount-time seed into a live cross-pane read: a toggle in one open combined-diff pane now flips sideBySide (and fileTreeCollapsed, same pattern below) in every other mounted pane the next time it re-renders. The previous code seeded useState once at mount, so simultaneously-mounted viewers stayed independent while still remembering the last choice on remount.
Technical details
# Shared preference read during render leaks across panes
## Affected sites
- src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-view-preferences.ts:35 — `sideBySide` derivation
- src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-view-preferences.ts:41 — `fileTreeCollapsed` derivation
- src/renderer/src/components/editor/combined-diff/remember-view/combined-diff-view-memory.ts:23 — `combinedDiffViewPreferences` is a module-level singleton shared by every mounted viewer
## Required outcome
- A toolbar toggle in one pane must not change the layout of another simultaneously-mounted pane unless that live sync is explicitly intended. If it is intended, the preference must be reactive (a store subscription) rather than picked up opportunistically on unrelated re-renders.
## Suggested approach (optional)
- Restore mount-time seeding: initialize the override state once from `combinedDiffViewPreferences` in a `useState` initializer, or lift `combinedDiffViewPreferences` into the zustand store so derived reads re-render subscribers consistently.|
Closing: this is an internal cleanup of the combined-diff view with no user-visible change, and we decided not to invest further in it right now. Separately, testing found a pre-existing bug unrelated to this PR: clicking a file in the combined-diff file tree scrolls to the file above it; that will be tracked on its own. Thank you for the work. |

Follow-up to #17341.
Summary
Validation