Skip to content

fix v2 sidebar nav-away on workspace delete#3771

Merged
saddlepaddle merged 1 commit intomainfrom
fix-workspace-deletion-na
Apr 26, 2026
Merged

fix v2 sidebar nav-away on workspace delete#3771
saddlepaddle merged 1 commit intomainfrom
fix-workspace-deletion-na

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Apr 26, 2026

Summary

  • When the user deletes the workspace they're currently viewing, the sidebar's "navigate away to a sibling" logic was silently no-op'ing — leaving the user stranded on the deleted workspace's URL.
  • Root cause: useNavigateAwayFromWorkspace used useParams({ strict: false }) from a layout-level component, which didn't reliably surface the leaf route's workspaceId. The early-return if (params.workspaceId !== workspaceId) return; was firing even when the user was viewing the doomed workspace.
  • Switched to useMatchRoute({ to: "/v2-workspace/\$workspaceId", params, fuzzy: true }) — the same pattern useDashboardSidebarWorkspaceItemActions already uses for isActive.
  • Nav still happens at the very start of run() in useDestroyDialogState (before the dialog closes / markDeleting / destroy fires), so the user moves off the doomed URL as soon as they confirm.

Test plan

  • On v2, with 2+ workspaces, view workspace A → right-click A in sidebar → Delete → confirm. Expect to land on workspace B (next sibling) immediately, before the destroy completes.
  • Same flow with only one workspace: expect to land on /.
  • View workspace A, right-click workspace B in sidebar → Delete → confirm. Expect to stay on workspace A.
  • Force-delete path (dirty worktree → uncommitted-changes banner → confirm anyway): nav still happens up front.
  • Teardown-failed path: nav happens at start, error pane reopens after — user is on the new workspace, error pane is informational.

Summary by cubic

Fixes v2 sidebar navigation when deleting the current workspace. We now detect the active workspace reliably and navigate to the next workspace (or /) immediately after confirm, so users aren’t left on a deleted URL.

  • Bug Fixes
    • Replaced useParams({ strict: false }) with useMatchRoute against "/v2-workspace/$workspaceId" to correctly detect the active workspace.
    • On delete, navigate early to the next available workspace via navigateToV2Workspace, or to / if none exist.

Written for commit 253cccf. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Refined workspace navigation logic to ensure more reliable switching between workspaces and proper fallback to the home view when no alternative workspace is available.

The dashboard sidebar's navigate-away check used useParams({ strict:
false }) from a layout-level component, which didn't reliably surface
the leaf route's workspaceId — so deletion silently no-op'd the nav and
left the user on the doomed workspace's URL. Switch to useMatchRoute
(the same pattern the sidebar item uses for isActive).
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2190f688-7cda-4add-a502-2be16001d82f

📥 Commits

Reviewing files that changed from the base of the PR and between ccf1f65 and 253cccf.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useNavigateAwayFromWorkspace/useNavigateAwayFromWorkspace.ts

📝 Walkthrough

Walkthrough

The useNavigateAwayFromWorkspace hook's implementation has been refactored to determine route navigation using useMatchRoute with fuzzy matching against /v2-workspace/$workspaceId, replacing direct useParams read. Navigation-away logic is now gated on this route match; the external interface remains unchanged.

Changes

Cohort / File(s) Summary
Route Matching Refactor
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useNavigateAwayFromWorkspace/useNavigateAwayFromWorkspace.ts
Changed from using useParams to useMatchRoute for determining workspace route context; navigation logic is now gated on fuzzy route match. Fallback behavior to / remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 With fuzzy matching hops so fine,
Route detection now does shine,
No more params scattered about,
Just match and navigate without doubt!
A rabbit's refactor, clean and neat,
Making workspace flows complete!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix v2 sidebar nav-away on workspace delete' clearly summarizes the main change: fixing navigation behavior when deleting a workspace in the v2 sidebar.
Description check ✅ Passed The description includes all required template sections: a comprehensive summary explaining the bug and fix, related issues context, type of change (bug fix), detailed testing scenarios, and additional implementation notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-workspace-deletion-na

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.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

This PR fixes a silent no-op in the "navigate away from a deleted workspace" logic by replacing useParams({ strict: false }) with useMatchRoute(), mirroring the same pattern already used in useDashboardSidebarWorkspaceItemActions for isActive. The change is minimal, targeted, and correctly threads the workspaceId param into the imperative matchRoute call inside the returned callback.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correct, and follows the established pattern in the codebase.

The change replaces a fragile useParams({ strict: false }) comparison with useMatchRoute(), which reads router state imperatively at call time rather than at render time. This directly resolves the root cause. No P0 or P1 issues identified; the logic, dependency array in useCallback, and fuzzy: true flag all look correct.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useNavigateAwayFromWorkspace/useNavigateAwayFromWorkspace.ts Replaces unreliable useParams({ strict: false }) with useMatchRoute() for detecting the current workspace; aligns with the existing isActive pattern in the sidebar item actions hook.

Sequence Diagram

sequenceDiagram
    participant User
    participant DestroyDialog as useDestroyDialogState
    participant NavAway as useNavigateAwayFromWorkspace
    participant Router as TanStack Router

    User->>DestroyDialog: confirm delete
    DestroyDialog->>NavAway: navigateAway(workspaceId)
    NavAway->>Router: matchRoute({ to: "/v2-workspace/$workspaceId", params: { workspaceId }, fuzzy: true })
    Router-->>NavAway: isViewingWorkspace (true/false)
    alt isViewingWorkspace = true
        NavAway->>Router: navigateToV2Workspace(next) or navigate("/")
        Router-->>User: redirected to sibling or home
    else isViewingWorkspace = false
        NavAway-->>DestroyDialog: no-op (user is on a different workspace)
    end
    DestroyDialog->>DestroyDialog: onOpenChange(false), markDeleting, destroy()
Loading

Reviews (1): Last reviewed commit: "fix v2 sidebar nav-away on workspace del..." | Re-trigger Greptile

@saddlepaddle saddlepaddle merged commit 2c119ad into main Apr 26, 2026
6 of 7 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch

Thank you for your contribution! 🎉

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