Skip to content

fix(diff-comments): stop review refreshes from blanking inline comment cards - #18142

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-diff-comment-zone-orphaning
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-diff-comment-zone-orphaning

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​284 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​284
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23

ELI5

Every time Orca refreshed a pull request, it deleted the contents of every inline comment box in the diff but left the empty boxes behind — so you got blank gaps where your review comments used to be. Then it did it again on the next refresh, stacking up more blank gaps.

What was wrong

useDiffCommentDecorator memoized commentableLineSet on the identity of the commentableLineNumbers array:

const commentableLineSet = useMemo(
  () => (commentableLineNumbers ? new Set(commentableLineNumbers) : null),
  [commentableLineNumbers]
)

On review surfaces that array is fileByPath.get(path)?.reviewCommentLineNumbers (pull-request-page/files/combined-diff-viewer.tsx:362, github-item-dialog/inspect-pull-request/pr-files-combined-diff-body.tsx:154). It is rebuilt fresh in the main process on every fetch (src/main/github/pull-request-file-data.ts:148) and shipped over IPC, and the renderer never value-compares it. So an identical set of line numbers still produced a new array -> new Set -> new dep.

That dep sat on the effect that owns both the add-button overlay and the view-zone teardown. Its cleanup unmounted every comment card's React root and emptied zonesRef, but never called accessor.removeZone. The effect that actually creates zones does not depend on commentableLineSet, so it never re-ran. Net result per refresh: Monaco still holds the view zones (still consuming vertical space), they are now blank, untracked, unremovable, and never re-rendered. If new review comments arrived between refreshes, the now-empty map made the create-effect rebuild zones for every comment on top of the stranded ones — quadratic accumulation.

Local worktree diffs were unaffected: CombinedDiffViewer.tsx does not pass getCommentableLineNumbers, so the set is null and stable.

The fix

  1. Memoize on the values, not the array identity (commentableLineNumbers?.join(',')). This kills the churn at the root and follows the existing house pattern in combined-diff-viewer.tsx (diffEntrySignature).
  2. Split the effect. commentableLineSet does not belong on the zone-teardown effect — but it cannot simply be dropped, because installDiffCommentAddButtonOverlay closes over the set by value and would go stale (the "+" button would keep offering the old commentable lines). So the overlay moved into its own effect ([addButtonLabel, commentableLineSet, editor, monacoModelIdentity]) and the teardown kept only [cancelScrollToZoneFrame, editor, monacoModelIdentity]. The teardown's deps are now a strict subset of the zone-creating effect's, which is the invariant that was missing: a teardown is now always followed by a rebuild.
  3. The missing accessor.removeZone was a second, real bug, latent even after the memo fix. The cleanup clears zonesRef, so anything left in Monaco is unreachable by definition. It still fires on a genuine model swap under a retained editor, and on any future dep added to that effect. Verified safe in monaco-editor: ViewZones._removeZone is guarded by hasOwnProperty (no-op for an id Monaco already dropped on model swap), and CodeEditorWidget.changeViewZones early-returns when _modelData is null (no-op on a disposed editor).

Measurements

Real numbers from the new regression suite (useDiffCommentDecorator.commentable-lines.test.tsx), same test run against unmodified main and against this branch.

Scenario A — 5 refreshes shipping value-equal line numbers, fixed set of 3 review notes:

createRoot calls root unmounts Monaco view zones orphaned (blank) zones
before 3 3 3 3
after 3 0 3 0

All three cards were destroyed; all three zones survived as blank gaps.

Scenario B — 5 refreshes, each also bringing one new review comment (6 notes live at the end):

createRoot calls root unmounts Monaco view zones orphaned (blank) zones
before 21 15 21 15
after 6 0 6 0

Scenario C — model swap under a retained editor: before, 2 view zones for 1 comment (1 stranded); after, 1.

Failing assertions on unmodified code

× keeps every comment root and view zone alive across value-equal review refreshes
AssertionError: expected { createRootCalls: 3, …(2) } to deeply equal { createRootCalls: 3, …(2) }
    "createRootCalls": 3,
    "monacoViewZones": 3,
-   "rootUnmounts": 0,
+   "rootUnmounts": 3,

× does not accumulate orphan zones when refreshes interleave with new review comments
AssertionError: expected { createRootCalls: 21, …(2) } to deeply equal { createRootCalls: 6, …(2) }
-   "createRootCalls": 6,
-   "monacoViewZones": 6,
-   "rootUnmounts": 0,
+   "createRootCalls": 21,
+   "monacoViewZones": 21,
+   "rootUnmounts": 15,

× rebuilds the add-button overlay when the commentable lines really change
AssertionError: expected { createRootCalls: 1, …(2) } to deeply equal { createRootCalls: 1, …(2) }
    "createRootCalls": 1,
    "monacoViewZones": 1,
-   "rootUnmounts": 0,
+   "rootUnmounts": 1,

× removes its zones from Monaco when the model swaps under a retained editor
AssertionError: expected 2 to be 1 // Object.is equality

All 4 fail on main, all 4 pass on this branch.

Tests

New src/renderer/src/components/diff-comments/useDiffCommentDecorator.commentable-lines.test.tsx drives the hook against a fake Monaco editor with a real view-zone registry and a createRoot counter scoped to zone containers:

  • value-equal refreshes: no extra createRoot, no unmounts, constant zone count, and a subsequent comment deletion still reclaims the zone (proving the zones stayed tracked, not just present)
  • refreshes interleaved with new comments: no orphan accumulation
  • a genuine change to the commentable line set is not made stale — widening [10,11,12] to [10,11,12,40] makes the "+" button appear on line 40, while the existing note's zone and React root are neither rebuilt nor orphaned
  • model swap under a retained editor removes the stale zone ids

Provider coverage

The fix lives in the provider-generic decorator hook, so any review surface inherits it. Today only the GitHub path populates reviewCommentLineNumbers (src/main/github/pull-request-file-data.ts); GitLab / Bitbucket / Azure DevOps MR views do not pass getCommentableLineNumbers yet, so they cannot hit the bug today and will be safe when they do. Naming and comments in the changed code say "PR/MR" rather than GitHub-specific terms.

Negative user-facing trade-offs

None. This is a strict improvement: it fixes visible blank gaps in the reviewed diff and stops inline comment cards from being wiped on every PR refresh. It also does strictly less work — fewer React root teardowns and, in the interleaved case, 21 -> 6 createRoot calls. The only behavior that can now differ is a genuine model swap, where stale view zones are removed instead of being left behind; the zone-creating effect re-runs on the same dep and rebuilds them, which the model-swap test asserts.

Verification

  • pnpm tc — clean
  • npx oxlint <changed files> — clean
  • npx vitest run --config config/vitest.config.ts src/renderer/src/components/diff-comments src/renderer/src/components/pull-request-page src/renderer/src/components/github-item-dialog — 12 files, 64 tests passed
  • npx vitest run --config config/vitest.config.ts src/renderer/src/components/editor — 192 files, 1295 tests passed (the hook's two consumers live there)

…t cards

commentableLineSet was memoized on array identity. Review surfaces hand the
decorator a fresh-but-equal number[] on every PR/MR data refresh, so the set
churned, tore down the overlay+zone effect (unmounting every comment card's
React root and clearing the zone map) while the zone-creating effect — which
does not depend on the set — never re-ran. Monaco kept the view zones as
untracked blank gaps, and the next refresh stacked more on top.

- memoize the set on a joined value key so equal refreshes are a no-op
- split the add-button overlay (needs the set) from the zone teardown (must
  not), so the teardown's deps stay a subset of the zone-creating effect's
- have the teardown actually removeZone what it stops tracking
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 1766f887-0977-4642-9e62-bfdf7a16124e

📥 Commits

Reviewing files that changed from the base of the PR and between f37d2fe and f5e0f68.

📒 Files selected for processing (2)
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.commentable-lines.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The hook now treats commentable-line arrays by value, separates add-button overlay cleanup from view-zone teardown, and removes tracked Monaco zones before unmounting roots. New tests track editor zones and React roots across equivalent refreshes, added comments, changed commentable lines, and Monaco model identity changes.

Merge Risk: ⚪ Minimal · up to f5e0f

This change prevents inline diff comments from becoming blank or accumulating duplicate spacing during refreshes while preserving correct behavior when commentable lines or models genuinely change. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, implementation, regression tests, provider coverage, trade-offs, and verification results. However, it leaves the required Linked Issue empty, omits the required Visu… Add a valid issue reference after "Fixes #". Add before-and-after screenshots or a video, or state "N/A" with a reason only if there is truly no visual or interaction change. Complete the required Testing, AI Disclosure, Review, Agent skill…
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. 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 describes the primary fix: preventing inline diff comment cards from becoming blank during review refreshes.
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 explains the bug, implementation, regression tests, provider coverage, trade-offs, and verification results. However, it leaves the required Linked Issue empty, omits the required Visual Proof section for this UI behavior change, and does not include the template checklist and related review sections.

Resolution

Add a valid issue reference after "Fixes #". Add before-and-after screenshots or a video, or state "N/A" with a reason only if there is truly no visual or interaction change. Complete the required Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.

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

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

✅ No new issues found.

Reviewed changes

  • Value-keyed memoization — commentableLineSet now memoizes on commentableLineNumbers?.join(',') instead of array identity, matching the existing diffEntrySignature pattern in combined-diff-viewer.tsx.
  • Effect split — the add-button overlay install and the zone teardown are now separate effects. Teardown deps ([cancelScrollToZoneFrame, editor, monacoModelIdentity]) are a strict subset of the zone-creating effect's deps, so a teardown is always followed by a rebuild.
  • Explicit removeZone — the teardown cleanup now drops zones from Monaco rather than only clearing the local map.
  • Regression suite — a new 4-test suite drives the hook against a fake editor with a real view-zone registry and a createRoot counter scoped to zone containers.

I verified the two load-bearing Monaco claims against [email protected] source: CodeEditorWidget.changeViewZones early-returns when _modelData is null (disposed editor), and ViewZones._removeZone is guarded by hasOwnProperty (no-op for ids Monaco already dropped on model swap). Both hold, so the new removeZone call is safe in the dispose and model-swap paths.

The test assertions are exact (e.g. createRootCalls: 3, rootUnmounts: 0, monacoViewZones: 3), not loose truthiness checks, and each one targets a distinct failure mode of the pre-fix code. I confirmed the suite and the existing model-lifecycle test pass locally, and oxlint is clean on both changed files.

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

@nwparker
nwparker merged commit 5510ad0 into main Sep 2, 2026
29 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…t cards (stablyai#18142)

commentableLineSet was memoized on array identity. Review surfaces hand the
decorator a fresh-but-equal number[] on every PR/MR data refresh, so the set
churned, tore down the overlay+zone effect (unmounting every comment card's
React root and clearing the zone map) while the zone-creating effect — which
does not depend on the set — never re-ran. Monaco kept the view zones as
untracked blank gaps, and the next refresh stacked more on top.

- memoize the set on a joined value key so equal refreshes are a no-op
- split the add-button overlay (needs the set) from the zone teardown (must
  not), so the teardown's deps stay a subset of the zone-creating effect's
- have the teardown actually removeZone what it stops tracking
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