Skip to content

fix(rename): keep an inline rename whose field unmounts mid-edit - #46766

Merged
AmoabaKelvin merged 3 commits into
mainfrom
fix/rename-commit-on-unmount
Nov 22, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
fix/rename-commit-on-unmount

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

If you were renaming a workspace in the sidebar and that row went away before you pressed Enter or clicked elsewhere (for example, you scrolled a long workspace list until the row dropped out), the name you typed was lost. Now it's saved, just as it would be if you'd clicked away.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​95 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​95
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23

What Changed

  • Before: inline renames save on blur. React runs no onBlur for a focused field that unmounts, so a draft whose field unmounted mid-edit was silently dropped. The left sidebar list is virtualized (overscan 10), so scrolling an edited row far enough unmounts it.
  • After: a shared useBlurSaveOnUnmount(isEditing, save) in lib/text-input/focus/ saves the draft on unmount while the field is still editing. It's used by the workspace title rename (sidebar rows, bot rows, hovercard, header), the bot name editor and the terminal tab rename.
  • The unmount save requires both the committed editing state and the editor's synchronous flag. That way an Escape that unmounts the field mid-cancel stays a cancel, and a card that remounts the title as renaming starts can't write back a stale name.
  • A failed rename now shows its error toast even after the field is gone.

Why

The draft is lost where the field decides to save, so that's where the fix goes: the editor saves itself when it goes away, instead of every caller trying to blur it first. File renames in the editor tab and editor header are left out on purpose. They rename files on disk, and they usually unmount because the file or tab went away. Settings fields and dialog title fields are also left out, because their exits either blur first or treat Escape as cancel.

Linked Issue

Found while fixing sidebar toggle focus (#46735). No issue filed.

Visual Proof

N/A: nothing on screen changes. The typed name is now kept instead of dropped. A scripted repro on a real build (100 workspaces, rename a row, scroll it out and back) showed the old name on main and the new name with this change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

WorktreeTitleInlineRename.unmount.test.tsx covers three cases, each failing without its part of the fix:

  • unmounting mid-edit saves the draft (fails with no hook);
  • an Escape whose cancel unmounts the field doesn't save (fails with the committed state alone);
  • a parent remounting the title as renaming starts doesn't write back a stale name (fails with the synchronous flag alone).

The existing bot name and tab rename tests pass, and pnpm check:changed passed.

Performance

None, because the hook adds one useEffectEvent and one mount-only effect per rename component. It does no work per keystroke, and runs only when a component unmounts.

Risk

Low. The new behaviour only runs when a rename component unmounts while editing, and only saves a changed draft. An unchanged draft is a no-op cancel, and the existing save guards stop double commits. One accepted edge: if a workspace is removed by another client while you're mid-rename with a changed name, that name is still written. A plain revert restores the old behaviour.

Level: Low

AI Disclosure

Review

Codex plus a Claude reviewer, three rounds.

  • Round 1 found that a cancel could unmount the editor before its state committed and so save a discarded draft. Fixed by reading a synchronous flag.
  • Round 2 found that a card remounting the title as renaming starts could write back a stale name. Fixed by also requiring the committed state.
  • Round 3 was clean. Each fix has a component test.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Not fixed here: in new or compact card styles, a card with hover details moves its title to a new tree position when renaming starts. That remounts the title, so a double-click rename doesn't open the editor there. It's a separate, older bug.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

React runs no onBlur for a focused field that unmounts, so a workspace, bot
or terminal tab rename that saves on blur lost the typed name when its row
scrolled out of the virtualized sidebar list or its owner went away. A shared
useBlurSaveOnUnmount hook commits the draft on unmount while still editing.
A cancel can unmount the editor before its editing=false state commits (a
card that draws the title elsewhere while renaming), so the unmount save
treated a cancelled rename as in progress. The hook now takes a getter, and
the workspace rename reads editingRef. A failed unmount save still toasts,
and a component test replaces the e2e at the layer that owns the save.
…ill editing

A card that remounts the title as renaming starts unmounted an instance whose
editingRef was set but whose editing state never committed, and the unmount
save wrote its stale value back. Require both the committed editing state
and the synchronous flag.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The change adds useBlurSaveOnUnmount and uses it in bot, worktree title, and terminal tab rename flows. The hook calls the save callback on unmount when editing remains active. Worktree title rename failures are toasted after unmount, while saving-state updates remain guarded by the mounted check. New tests cover hiding the editor during a rename, Escape cancellation, and title movement when renaming starts.

Merge Risk: Low · up to d344b

Inline renames now survive the editor unmounting. Two small edge cases remain: an untouched terminal tab rename can freeze the tab name, and a workspace rename can occasionally be submitted twice. Both are worth fixing but are not serious.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(rename): keep an inline rename whose field unmounts mid-edit" names the main change: an inline rename draft is now saved when its field unmounts while editing. The raw summary confirms …
Description check Passed The description follows the template and covers each required section: ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk with level, AI Disclosure, Revi…
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: Title check

Explanation

The title "fix(rename): keep an inline rename whose field unmounts mid-edit" names the main change: an inline rename draft is now saved when its field unmounts while editing. The raw summary confirms the shared useBlurSaveOnUnmount hook and its use in the rename components, so the title matches the changeset. It is specific and conventional.

Full details: Description check

Explanation

The description follows the template and covers each required section: ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk with level, AI Disclosure, Review, upstream boundary, Notes, and Checklist. It explains the mechanism (blur does not fire on unmount), the synchronous flag and committed-state guard, the excluded areas, and the rollback path. Gaps: the Linked Issue section cites #46735 as the source of discovery and states no issue was filed, which the template does not accept for outside contributors. The Visual Proof section gives a scripted repro in prose rather than attached before/after media. The AI Disclosure section is empty. These are minor for a maintainer PR, but the Linked Issue gap could matter under the template's rule.

Resolution

Optional: confirm the author is a stablyai maintainer, since the template requires an actual linked issue for outside contributors. Consider attaching the before/after repro media in Visual Proof, and fill in the AI Disclosure section or confirm it does not apply.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bb6b74fb-8718-421f-93a9-cb7f89d63b53
Commits

Reviewing files that changed from the base of the PR and between 9999008 and d344bc1.

Files selected for processing: 5

  • src/renderer/src/components/bots/BotNameInlineEdit.tsx
  • src/renderer/src/components/sidebar/workspace-card/identity/WorktreeTitleInlineRename.tsx
  • src/renderer/src/components/sidebar/workspace-card/identity/WorktreeTitleInlineRename.unmount.test.tsx
  • src/renderer/src/components/tab-bar/terminal-tabs/use-sortable-tab-rename.ts
  • src/renderer/src/lib/text-input/focus/use-blur-save-on-unmount.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

}
}
}, [cancelRename, displayName, onRename, setEditingMode, value])
useBlurSaveOnUnmount(() => editing && editingRef.current, commitRename)

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.

Minor · Data Integrity & Integration · Quick win

Stop the unmount save from repeating a rename that already completed.

If the title detaches while onRename is pending, the save can complete before the passive cleanup of useBlurSaveOnUnmount runs. The completion skips setEditingMode(false) because mountedRef is false. editingRef stays true, and savingRef is cleared in finally. The cleanup then calls commitRename again with the same draft, so onRename can receive a second request for the same rename. If the second request fails, the error toast appears after the first rename has succeeded.

The fix must prevent the cleanup from saving a draft that has already been submitted and completed. It must also keep the stale-write guard for a title that remounts during a new edit. Do not clear editingRef only for unmounted completions, because that alone does not cover a remounted title.

Source: Learnings

setIsEditing(false)
}, [renameValue, onSetCustomTitle, tabId])

useBlurSaveOnUnmount(() => isEditing && !committedOrCancelledRef.current, commitRename)

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.

Minor · Functional Correctness · Quick win

Save only changed terminal drafts during unmount.

If customTitle is null, opening rename copies the automatic title into renameValue. Unmounting without typing now saves that value as customTitle. SortableTab then prefers this custom title over later automatic title updates, so an untouched edit freezes the tab name. Previously, this unmount did not create an override. (raw.githubusercontent.com)

Compare the draft with an opening-value snapshot before saving during cleanup. Do not compare it with the live title, which can change during editing. Preserve explicit Enter/blur behavior and changed-to-blank clearing.

This follows the PR objective to retain changed drafts.

@AmoabaKelvin
AmoabaKelvin merged commit e6d526a into main Nov 22, 2026
56 checks passed
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