Skip to content

fix(sidebar): fix rename input losing its selection on open#5563

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix-rename-deselect-text
Jul 10, 2026
Merged

fix(sidebar): fix rename input losing its selection on open#5563
waleedlatif1 merged 2 commits into
stagingfrom
fix-rename-deselect-text

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes rename occasionally deselecting the pre-highlighted text when opening the rename input for workflows, folders, and workspaces from the context/dropdown menu
  • Root cause: Radix's FocusScope defers its close-time focus teardown to a setTimeout(0), which can run after the rename input's own mount-time focus()/select() and clobber the selection — explains why it was intermittent rather than every time
  • Fix: focus + select the rename input from the shared ContextMenu's onCloseAutoFocus handler instead of a plain effect, since that callback runs synchronously inside Radix's own deferred teardown and always wins the race regardless of scheduler timing
  • Additive-only change (new optional renameInputRef prop on ContextMenu, wired from the three rename call sites) — every other ContextMenu consumer is unaffected

Type of Change

  • Bug fix

Testing

Verified via typecheck (clean, no new errors) and lint (clean), and traced the fix against Radix's actual FocusScope source to confirm the timing race it closes. Could not click through the live repro in this environment (no DB/auth available locally) — worth a manual pass before merge.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Radix's FocusScope defers close-time focus teardown to a setTimeout(0),
which can occasionally run after the rename input's own focus()/select()
and clobber the selection. Focus the input from onCloseAutoFocus instead,
which runs inside that same deferred teardown and always wins the race.

Affects workflow, folder, and workspace rename (all route through the
shared sidebar ContextMenu component).
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 10, 2026 5:47pm

Request Review

@cursor

cursor Bot commented Jul 10, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small, UI-only focus-handling change with an optional prop; no auth, data, or API impact.

Overview
Fixes an intermittent bug where Rename from the sidebar context menu opened the inline input but cleared the pre-selected name text.

The shared ContextMenu now accepts an optional renameInputRef and, when Rename is chosen, sets a flag so DropdownMenuContent's onCloseAutoFocus (still calling preventDefault) re-focuses and select()s that input. That runs in Radix's close focus teardown and wins the race against deferred FocusScope cleanup that could run after mount-time focus/select.

Ref wiring is limited to workflow, folder, and workspace rename call sites; other ContextMenu users are unchanged. A guard ensures only a Rename-driven menu close triggers refocus, so closing the menu for other actions does not steal focus from an active rename elsewhere.

Reviewed by Cursor Bugbot for commit 26f4482. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the sidebar rename focus race. The main changes are:

  • Adds a shared rename input ref path to the sidebar context menu.
  • Refocuses and selects the rename input from onCloseAutoFocus after Rename is selected.
  • Wires the rename ref through workflow, folder, and workspace rename call sites.
  • Gates the refocus so unrelated menu actions do not steal focus back into an active rename input.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu.tsx Adds the gated rename refocus behavior to the shared context menu.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/folder-item/folder-item.tsx Passes the folder rename input ref into the shared context menu.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/workflow-item/workflow-item.tsx Passes the workflow rename input ref into the shared context menu.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx Adds a workspace rename input ref and passes it into the shared context menu.

Reviews (3): Last reviewed commit: "fix(sidebar): only refocus the rename in..." | Re-trigger Greptile

… close

onCloseAutoFocus fires on every menu close, not just after selecting
Rename. Gate the refocus behind a ref set only when the Rename item
was selected, so closing the menu for an unrelated action (Delete,
Duplicate, ...) while an earlier rename is still live doesn't steal
focus back into it and delay its blur-save.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 26f4482. Configure here.

@waleedlatif1 waleedlatif1 merged commit 08320d5 into staging Jul 10, 2026
13 checks passed
@waleedlatif1 waleedlatif1 deleted the fix-rename-deselect-text branch July 10, 2026 17:55
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

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