Skip to content

fix(desktop): hoist mutation hooks out of Dialog to fix stale sidebar after workspace creation#2441

Merged
Kitenite merged 2 commits into
superset-sh:mainfrom
Kitenite:Kitenite/for-some-users-when-they-add-a-new-workspace-they
Mar 12, 2026
Merged

fix(desktop): hoist mutation hooks out of Dialog to fix stale sidebar after workspace creation#2441
Kitenite merged 2 commits into
superset-sh:mainfrom
Kitenite:Kitenite/for-some-users-when-they-add-a-new-workspace-they

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Mar 12, 2026

Summary

  • Root cause: When users create a workspace from the new-workspace modal, runAsyncAction closes the Dialog immediately. Radix Dialog unmounts its content, destroying useMutation observers inside PromptGroup, BranchesGroup, IssuesGroup, and PullRequestsGroup. If the mutation completes after unmount, onSuccess (containing utils.workspaces.invalidate() + navigation) is skipped — leaving the sidebar stale.
  • Fix: Hoist useCreateWorkspace, useCreateFromPr, useOpenTrackedWorktree, and useOpenExternalWorktree into NewWorkspaceModalDraftProvider, which wraps the Dialog and stays mounted. Content components now consume mutations from context.
  • Extracted inline openTrackedWorktree mutation from BranchesGroup into useOpenTrackedWorktree hook.
  • Moved resolveInitialCommands from a useCreateWorkspace hook option to a per-call PendingSetupOverrides parameter so the hook can be called without per-component options.

Test plan

  • Create a workspace from the Prompt tab — verify it appears in the sidebar without refresh
  • Create a workspace from the Branches tab — verify sidebar updates
  • Create a workspace from the Issues tab — verify sidebar updates
  • Create a workspace from the Pull Requests tab — verify sidebar updates
  • Import a tracked worktree from the Branches tab — verify sidebar updates
  • Import an external worktree from the Branches tab — verify sidebar updates
  • "Import all" worktrees button still works (stays in modal, not affected by this change)
  • Verify workspace creation from outside the modal (e.g. project page, command watcher) still works

Summary by cubic

Fixes stale sidebar after creating or importing a workspace from the New Workspace modal by moving mutation hooks out of the Dialog so onSuccess always runs. The sidebar now refreshes and navigation works without a reload.

  • Bug Fixes

    • Hoisted create/open mutations into NewWorkspaceModalDraftProvider, so Dialog unmounts don’t cancel observers.
    • Content groups (Prompt, Branches, Issues, PRs) now use mutations from context.
    • Sidebar updates immediately after creating from any tab or opening tracked/external worktrees.
  • Refactors

    • Added useOpenTrackedWorktree hook and re-exported it.
    • Updated useCreateWorkspace to accept per-call resolveInitialCommands via PendingSetupOverrides.

Written for commit 450a6cd. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Consolidated workspace creation and worktree management actions into a unified modal context for improved state management and consistency across workspace creation flows.
    • Enhanced command initialization for new workspaces with customizable resolution logic.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This change consolidates workspace and worktree management actions through a modal draft context. Four hooks (createWorkspace, createFromPr, openTrackedWorktree, openExternalWorktree) are centralized in a context provider and accessed via useNewWorkspaceModalDraft, replacing scattered individual hook imports across components.

Changes

Cohort / File(s) Summary
Context Provider Integration
apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModalDraftContext.tsx
Extends context shape with four new workspace/worktree actions (createWorkspace, createFromPr, openTrackedWorktree, openExternalWorktree) initialized as local hook constants within the provider to persist across dialog unmounts.
Component Hook Consolidation
apps/desktop/src/renderer/components/NewWorkspaceModal/components/BranchesGroup/BranchesGroup.tsx, IssuesGroup/IssuesGroup.tsx, PromptGroup/PromptGroup.tsx, PullRequestsGroup/PullRequestsGroup.tsx
Refactored components to consume workspace actions from useNewWorkspaceModalDraft instead of direct individual hook imports; PromptGroup adds resolveInitialCommands callback to mutation payload.
Hook Infrastructure
apps/desktop/src/renderer/react-query/workspaces/useCreateWorkspace.ts, useOpenTrackedWorktree.ts, index.ts
Enhanced useCreateWorkspace with resolveInitialCommands option for customizing initial command resolution; created new useOpenTrackedWorktree hook; added useOpenTrackedWorktree to public exports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A context so neat, where actions now dwell,
Four hooks consolidated—a refactoring spell!
From scattered imports to unified grace,
The workspace draft finds its rightful place.
Modal persistence, resolved commands too,
One hook to unite them—fresh paths to pursue! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: hoisting mutation hooks out of Dialog to resolve the stale sidebar issue after workspace creation.
Description check ✅ Passed The description fully addresses the template structure with a detailed summary, root cause analysis, and comprehensive test plan, though missing explicit GitHub issue links in the Related Issues section.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

@Kitenite Kitenite merged commit fc35b57 into superset-sh:main Mar 12, 2026
6 of 7 checks passed
@Kitenite Kitenite deleted the Kitenite/for-some-users-when-they-add-a-new-workspace-they branch March 12, 2026 23:51
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