Skip to content

bug(platform): after an organization switch from a page, Back re-runs the switch instead of going back #4254

Closed

Description

@yannickmonney

Summary

After you switch organization from any dashboard page, the browser's Back button can't take you back. Every Back press returns to /dashboard/switching?to=‹new org›&subpath=…, which runs the switch again and lands on the same page in the new organization. Back is trapped there; history doesn't even grow.

The switch route means to replace its history entry, but its subpath branch pushes:

// services/platform/app/routes/dashboard/switching.tsx:126–141 (main d29a3c8fe)
// Replace history entry so Back button doesn't return here. …
router.history.push(`/dashboard/${targetOrgId}/${targetSubpath}`, {
  replace: true,
});

TanStack History's signature is push(path, state?, navigateOpts?) (@tanstack/history 1.161.6, index.d.ts:19), so { replace: true } is stored as history state and the entry is pushed. The branch without a subpath uses navigate({ …, replace: true }), which replaces correctly.

The org switchers enter this route with replace: true (organization-list-panel.tsx:49–53), so the page you switched from is gone from history. The switching URL stays in its place, under the new page.

Source and environment

  • Source: origin/main d29a3c8fe78cdba54d247fe82ea5195f702c0651 (2026-10-04), in a detached worktree with no local changes.
  • Stack: an isolated local stack started with bun scripts/dev.ts.
    • Vite runs on localhost:3751 and the backend on 127.0.0.1:3756.
    • The occurrence has its own PostgreSQL on 127.0.0.1:55379, and egress goes to a dead proxy.
  • Owner: TALE-358 local-qa occurrence 2026-10-04 08:15 Zurich, run 01879aef-d562-4abd-b5b5-2b3bdf431a89.
  • Browser: headless Chromium 1208 (Playwright 1.58.2) at 1280×900, en-US.
  • Data: one synthetic owner of two organizations, A and B, each with one project.
  • Origin of the lead: first seen while reading code during TALE-540's evidence run (noted to TALE-359 as 1de47518); reproduced here.

Reproduction (the real journey)

  1. In organization A, open Chat, then Projects (/dashboard/‹A›/projects).
  2. Open Manage account › Organization and choose organization B.
    • Navigations: /dashboard/switching?to=‹B›&subpath=projects, then /dashboard/‹B›/projects.
    • history.length goes from 3 to 4.
  3. Press Back three times.
Step Observed URL after Back Navigations that Back caused history.length
Back 1 /dashboard/‹B›/projects switching?to=‹B›&subpath=projects → /dashboard/‹B›/projects 4
Back 2 /dashboard/‹B›/projects the same two 4
Back 3 /dashboard/‹B›/projects the same two 4

Each Back also flashes the "Switching to …" spinner and calls setActive again.

Controls

Case After the switch Back 1
No subpath (/dashboard/switching?to=‹B›, the navigate({ replace: true }) branch), loaded from A's Chat /dashboard/‹B›/chat /dashboard/‹A›/chat: Back works
With a subpath (…&subpath=projects), the same entry /dashboard/‹B›/projects /dashboard/‹B›/projects again: trapped
One-line swap in the worktree, router.history.replace(path), then the real journey /dashboard/‹B›/projects, history.length 3 /dashboard/‹A›/chat; Back 2 reaches the start of history
The same swap, with a subpath /dashboard/‹B›/projects /dashboard/‹A›/chat

The swap was reverted afterwards, and the worktree is clean.

Impact

  • Who's affected: anyone in more than one organization who switches from the user menu or Settings › Your organizations. That's nearly every switch, because the menu carries the current page as subpath.
  • What they can't do: go back with Back. Each press re-runs the switch to the organization they just left for, flashes a spinner and writes the active organization again.
  • The only ways out: typing a URL, or the long-press history menu.
  • Same branch, other callers: any switch with a subpath, including links that land on /dashboard/switching?to=…&subpath=….

Expected

Leaving through the switch replaces the switching entry, as the code comment says. Back after a switch then returns to the page before the one you switched from, as the no-subpath branch already does.

Acceptance checks

  1. Back escapes: after a user-menu switch from a page with a subpath, Back leaves organization B and doesn't revisit /dashboard/switching.
  2. The entry is replaced: /dashboard/switching?… never remains in history after a switch, with or without a subpath (history.length doesn't grow by the switch entry).
  3. A test pins replace semantics on both branches, for example a router-history spy asserting replace (not push) for the subpath path, or a browser test of Back.

Evidence and limits

  • Evidence kept locally (TALE-358 r20261004T0815):
    • the probe scripts/b1-org-switch-back.ts;
    • evidence/b1-org-switch-back-main.log and …-swapped.log;
    • evidence/b1-swap.diff;
    • screenshots in evidence/b1-main/ and b1-swapped/.
  • Limits:
    • Desktop Chromium only. The phone layout's switcher wasn't driven.
    • After Back to A's URL, the session's active organization stayed B for a few seconds, then followed the URL. That is the existing route guard and is not part of this report.

Activity

  1. yannickmonney commented on Oct 9, 2026

    @yannickmonney
    ContributorAuthor

    Post-merge recheck (Review A, 2026-10-10 00:15 Europe/Zurich)

    Static recheck at main e6fb96249, after #4410 merged at 2026-10-09T22:19:58Z (f31bc4021):

    • The root cause is gone. The subpath branch of routes/dashboard/switching.tsx now calls router.history.replace(…) through replaceDashboardPath. Acceptance checks 1 and 2 are met in source; the no-subpath branch already used navigate({ …, replace: true }).
    • Acceptance check 3 is only partly met. switching.test.tsx calls replaceDashboardPath directly with a stub history. Reverting the route to history.push(…, { replace: true }) would not fail it, and the no-subpath branch isn't pinned. A route-level history spy, or a browser test of Back, would pin the behaviour.
    • Not re-run live. I didn't repeat the Chromium Back journey from the original report, because the local stack is blocked by the missing heavy-phase reservation. The Review A cell goes back to BLOCKED, not PASS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions