Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 6 remain after this review. 📝 WalkthroughWalkthroughDiff content now records load failures with Merge Risk: ⚪ Minimal · up to The change prevents a failed diff-load message from being saved over the user's file by making the error pane read-only; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
When a diff RPC fails, useEditorPanelContentState fabricates a result whose
modifiedContent is \`Error loading diff: \${err}\` so the pane has something to
show. For an unstaged diff that pane is editable, so Cmd+S calls onSave with the
editor body — and attemptEditorFileSave falls back to that body when no draft
exists (editor-autosave-controller). The error sentence gets written over the
user's file.
Reachable from any diff-load failure: SSH drop, git error, permission denied, or
the diff_too_large introduced in #14160.
The existing largeDiffSaveContentAvailable guard does not cover this. It only
gates the LargeDiffFallback button, which renders when largeDiffRenderLimit is
limited; on the error path that field is absent, so the full editable DiffEditor
mounts and installs the save shortcut instead.
Marks the fabricated result and holds the pane read-only, which blocks the save
shortcut and prevents a draft being minted — a draft would otherwise be saveable
even with onSave gated. loadError mirrors the field FileContent already carries
for the plain-file path, and lives on the renderer-local DiffContent, so nothing
on the wire changes.
Test: mutation-verified — dropping the guard fails exactly the new read-only
case. 23094 renderer tests pass; web and node typechecks clean.
Co-authored-by: Orca <[email protected]>
…covers Two problems with gating the diff pane on the fetch outcome alone: The pane renders `modifiedDiffBuffer ?? dc.modifiedContent`, so when a draft exists it shows the user's own text, not the error message. Holding that read-only froze a dirty tab with a dead Cmd+S and no explanation. Gate on what is actually rendered instead — the error body can only reach the editor when there is no draft. This also made a diff pane's `editable` dynamic for the first time, and DiffViewer wired editing only in onMount, which @monaco-editor/react pins to the first render. A pane recovering from a failed load became typable with no save shortcut and no change subscription: keystrokes minted no draft, the tab never went dirty, and the text was lost on the next remount. Move that wiring into an effect keyed on `[editable, modifiedEditor]`. Remounting would have worked too, but the mount-time focus grab would steal keystrokes, since the recovery is an unattended background refetch. Also drops loadError when a save replaces the body, so the pane does not stay read-only while showing correct on-disk content.
f0de825 to
56c307d
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Adapted from #14509 to the current split editor surface. Co-authored-by: Orca <[email protected]>
|
Closing as superseded by the still-open #25407, which explicitly adapts this fix to the current editor modules. I compared all six production files in this PR with the replacement. #25407 carries the renderer-local The hook extraction in this version is replaced by the same effect lifetime directly in |
The bug
When a diff RPC fails,
useEditorPanelContentStatefabricates a result so the pane has something to render:For an unstaged diff that pane is editable.
Cmd+ScallsonSave(modifiedEditor.getValue()), andattemptEditorFileSavefalls back to the displayed body when no draft exists (editor-autosave-controller.ts). The error sentence gets written over the user's file.Reachable from any diff-load failure — SSH drop, git error, permission denied, or the
diff_too_largeadded in #14160.Why the existing guard misses it
largeDiffSaveContentAvailablealready exists for exactly this hazard, but it only gates theLargeDiffFallbackbutton, which renders whenlargeDiffRenderLimit.limitedis true. On the error path that field is absent, sorenderLimit.limitedis false, the fullDiffEditormounts, andinstallEditorSaveShortcutis installed — gated only byeditable. The guard never runs.The fix
Mark the fabricated result and hold the pane read-only.
Read-only rather than just gating
onSave, because a draft is the other route: typing into the pane mints one viaonContentChange, and a draft is saveable even when the fallback body is not.editable={false}closes both —installEditorSaveShortcutsits insideif (editable).loadErrormirrors the fieldFileContentalready carries for the plain-file path, and lives on the renderer-localDiffContent(GitDiffResult & {...}), so nothing on the wire changes.Scope
4 files, +138/−6 — most of it the new test.
editor-panel-content-types.tsloadError?: booleanonDiffContentuseEditorPanelContentState.tsEditorContent.tsxdiffEditablegateseditable/onContentChange/onSaveEditorContent.diff-load-error.test.tsxTesting
diffEditableto plainisEditablefails exactly the new read-only case, and only that case.Not in scope
The error pane's presentation is unchanged — it still shows the message inside a diff view rather than the dedicated
FileLoadErrorViewthe plain-file path uses. That is a UX improvement worth doing separately; this PR only removes the data-loss path.Made with Orca 🐋