You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(rename): keep an inline rename whose field unmounts mid-edit - #46766
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.
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: 4
Check name
Status
Explanation
Title check
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
What Changed
onBlurfor 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.useBlurSaveOnUnmount(isEditing, save)inlib/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.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
mainand the new name with this change.Testing
WorktreeTitleInlineRename.unmount.test.tsxcovers three cases, each failing without its part of the fix:The existing bot name and tab rename tests pass, and
pnpm check:changedpassed.Performance
None, because the hook adds one
useEffectEventand 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.
Agent skill upstream boundary
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)