fix(desktop): stop workspace delete from crash-remounting the renderer via stale v1 routes

Merged
KI
3mo ago
+34-6

Fixes SUPER-1814 — reported by Jose Carlos (reacherapp.com) on 1.20.2: every workspace delete "refreshes the whole Superset application" and dumps him on an empty New Workspace screen until a manual reload.

Root cause

Confirmed against his PostHog timeline (the desktop_opened root-mount event re-fires 400ms after each delete, landing on #/new-workspace):

  1. Deleting the active workspace with no visible sibling falls back to navigate({ to: "/" }).
  2. / redirects to /workspace — the v1 index.
  3. For migrated v2 users, the v1 index restores a stale lastViewedWorkspaceId (pre-migration v1 row still in the electron localDb) and navigates onto a v1 workspace route.
  4. The dashboard's version-mismatch guard rendered an inline <Navigate to="/new-workspace" replace />. Navigate re-navigates whenever its props object identity changes, so every layout re-render during the pending navigation re-navigated until React threw error #185. The throw bubbled to the root errorComponent, unmounting the entire tree; the settled navigation reset the boundary and remounted the root — the "app reloaded itself" flash.

Only users with pre-migration v1 leftovers hit this, which is why it never reproduced on clean installs. Step 4 is the same hazard class already fixed in routes/page.tsx (#5729).

Fix

  • Hoist the version-mismatch <Navigate> to module scope for stable props identity — kills the #185 loop no matter how a v2 user reaches a v1 route.
  • Workspace-removal fallback goes straight to /new-workspace instead of detouring through / → v1 index.
  • The v1 workspace index redirects v2 users to /new-workspace instead of running v1 restore logic — covers every other path into / (sign-in, create-organization, not-found "Go home"), including the sibling "creating a workspace makes the others disappear" symptom in the same report.

Verification

  • Mechanism confirmed in the installed router source: Navigate re-navigates on props-identity change (useNavigate.js, previousPropsRef.current !== props).
  • bun run typecheck (desktop) clean, bun run lint clean, 1454 renderer tests pass.
  • No end-to-end CDP repro was run — reproducing requires seeding pre-migration v1 state (stale lastViewedWorkspaceId + v1 localDb rows).

Summary by cubic

Fixes SUPER-1814 by stopping the app from remounting after deleting a workspace. V2 users now go straight to /new-workspace, avoiding stale v1 routes and a Navigate re-navigation loop.

  • Bug Fixes
    • Hoisted version-mismatch Navigate to module scope to keep props stable and prevent re-navigation (React error 185).
    • On delete fallback, route directly to /new-workspace instead of "/" → v1 index.
    • In the v1 workspace index, detect v2 and redirect to /new-workspace; skip electronTrpc.workspaces.getAllGrouped for v2; isolate the v2 redirect from v1 query churn and memoize the workspace list to avoid redundant effect triggers during navigation.

Summary by CodeRabbit

  • New Features

    • Added automatic navigation to the new workspace setup when no replacement workspace is available.
    • Added routing from V2 Cloud workspace dashboards to the new workspace experience.
  • Bug Fixes

    • Improved workspace restoration and navigation behavior for existing V1 workspaces.
    • Prevented unnecessary workspace reloads during dashboard navigation.