Skip to content

fix(combined-diff): resolve React Doctor findings - #17506

Closed
AmethystLiang wants to merge 1 commit into
mainfrom
fix/combined-diff-static-analysis
Closed

AmethystLiang wants to merge 1 commit into
mainfrom
fix/combined-diff-static-analysis

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 0 0 0 0
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​371 $\color{#cf222e}{\Huge{\mathbf{−}}}$​272 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​99

Follow-up to #17341.

Summary

  • Resolve the changed-line React Doctor findings in the combined-diff refactor without suppressions.
  • Apply the remaining focused CodeRabbit feedback for scroll persistence and localization naming.
  • Preserve the existing combined-diff behavior and add no unrelated cleanup.

Validation

  • Changed code quality and React Doctor checks: 0 findings
  • Typecheck: passed
  • Combined-diff tests: 59 passed
  • Localization catalog, extraction, and coverage checks: passed

@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

This 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.

  • Extracts the combined-diff presentation into CombinedDiffViewerContent.
  • Moves render-time ref assignments into layout effects and derives preferences without synchronization effects.
  • Updates filtering, toolbar button types, localization naming, and loaded-section revalidation.
  • Changes scroll cleanup behavior, but the new captured-anchor handling can restore a stale position.

Confidence Score: 4/5

The 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

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix(combined-diff): resolve static analy..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The combined-diff viewer now delegates rendering to CombinedDiffViewerContent and reloads loaded sections when automatic Git-status changes occur. Related hooks move ref synchronization into layout effects and derive view preferences from overrides. File filtering, navigation props, toolbar buttons, scrolling, and note handling were updated. New localized note-clearing messages were added. React Doctor suppressions were removed from the quality checks.

Merge Risk: 🔵 Low · up to cb875

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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,… 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 …
Docstring Coverage ⚠️ Warning 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: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: resolving React Doctor findings in the combined-diff implementation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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 Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d341c1 and cb875ad.

📒 Files selected for processing (20)
  • config/scripts/check-changed-code-quality.mjs
  • package.json
  • src/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsx
  • src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-filter.ts
  • src/renderer/src/components/editor/combined-diff/browse-files/use-combined-diff-tree-navigation.ts
  • src/renderer/src/components/editor/combined-diff/combined-diff-viewer-content.tsx
  • src/renderer/src/components/editor/combined-diff/load-sections/combined-diff-section-load-registry.ts
  • src/renderer/src/components/editor/combined-diff/load-sections/use-combined-diff-section-revalidation.ts
  • src/renderer/src/components/editor/combined-diff/remember-view/use-combined-diff-view-restore.ts
  • src/renderer/src/components/editor/combined-diff/review-controls/combined-diff-toolbar.tsx
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-notes-actions.ts
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.ts
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-view-preferences.ts
  • src/renderer/src/components/editor/combined-diff/scroll-viewport/combined-diff-section-list.tsx
  • src/renderer/src/components/editor/combined-diff/scroll-viewport/use-combined-diff-scroll-persistence.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 reactDoctor ignore overrides from package.json and the SUPPRESSED_REACT_DOCTOR_DIAGNOSTICS filter from the changed-code-quality script.
  • Fixed no-ref-current-in-render — moved render-phase ref.current writes into useLayoutEffect in the load registry, tree navigation, and section actions hooks.
  • Replaced derived state with render-time derivation — sideBySide/fileTreeCollapsed now derive from override state plus the module preference instead of seeded useState + syncing effects.
  • Extracted CombinedDiffViewerContent — moved the JSX body into its own component and collapsed the section list's three mode booleans into a single mode prop derived from treeMode.
  • Relocated the git-status reload effect from useCombinedDiffSectionRevalidation into CombinedDiffViewer (behavior-equivalent).
  • Applied CodeRabbit feedback — toSorted instead of copy+sort, a semantic localization key, and capturing the DOM scroll anchor ref once at effect setup.

ℹ️ Nitpicks

  • The old localization key 45cf23b418 was left in all five locale files after the rename to failedToClearNotes. It is now an orphan (harmless — the extraction check only reports orphans) but can be removed for cleanliness.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment on lines +35 to +38
const sideBySide =
sideBySideOverride ??
combinedDiffViewPreferences.sideBySide ??
diffDefaultView === 'side-by-side'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

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.

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