Repository navigation
fix(diff-comments): stop review refreshes from blanking inline comment cards - #18142
Conversation
…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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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.
✨ 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
- Value-keyed memoization —
commentableLineSetnow memoizes oncommentableLineNumbers?.join(',')instead of array identity, matching the existingdiffEntrySignaturepattern incombined-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
createRootcounter 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…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

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
useDiffCommentDecoratormemoizedcommentableLineSeton the identity of thecommentableLineNumbersarray: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 -> newSet-> 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 calledaccessor.removeZone. The effect that actually creates zones does not depend oncommentableLineSet, 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.tsxdoes not passgetCommentableLineNumbers, so the set isnulland stable.The fix
commentableLineNumbers?.join(',')). This kills the churn at the root and follows the existing house pattern incombined-diff-viewer.tsx(diffEntrySignature).commentableLineSetdoes not belong on the zone-teardown effect — but it cannot simply be dropped, becauseinstallDiffCommentAddButtonOverlaycloses 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.accessor.removeZonewas a second, real bug, latent even after the memo fix. The cleanup clearszonesRef, 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 inmonaco-editor:ViewZones._removeZoneis guarded byhasOwnProperty(no-op for an id Monaco already dropped on model swap), andCodeEditorWidget.changeViewZonesearly-returns when_modelDatais null (no-op on a disposed editor).Measurements
Real numbers from the new regression suite (
useDiffCommentDecorator.commentable-lines.test.tsx), same test run against unmodifiedmainand against this branch.Scenario A — 5 refreshes shipping value-equal line numbers, fixed set of 3 review notes:
createRootcallsAll 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):
createRootcallsScenario C — model swap under a retained editor: before, 2 view zones for 1 comment (1 stranded); after, 1.
Failing assertions on unmodified code
All 4 fail on
main, all 4 pass on this branch.Tests
New
src/renderer/src/components/diff-comments/useDiffCommentDecorator.commentable-lines.test.tsxdrives the hook against a fake Monaco editor with a real view-zone registry and acreateRootcounter scoped to zone containers:createRoot, no unmounts, constant zone count, and a subsequent comment deletion still reclaims the zone (proving the zones stayed tracked, not just present)[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 orphanedProvider 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 passgetCommentableLineNumbersyet, 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
createRootcalls. 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— cleannpx oxlint <changed files>— cleannpx 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 passednpx vitest run --config config/vitest.config.ts src/renderer/src/components/editor— 192 files, 1295 tests passed (the hook's two consumers live there)