feat(webapp): stay on the same page when switching project or organization - #4585
Merged
Conversation
…ation The project and organization switchers carried you to the Tasks page of wherever you landed. They now carry the page you were on: the switcher link names it, and the project index loader appends it to the environment it already resolves, so the environment is still picked server-side. Pages named after a resource truncate to their list page, from one list shared with the environment switcher — which previously only truncated runs, deploys and schedules, and so carried ids from the other 16 into the new environment.
|
Contributor
Author
|
@coderabbitai review Generated by Claude Code |
Portability is two properties, not one: the branch lists render under any environment of their project, so an environment switch keeps them — as it did before the page-carrying switchers existed — while a project or organization switch still falls back to Tasks, since the project it opens may have no preview branches. A test locks the environment half: every page below an environment that names no resource has to survive an environment switch, which is exactly what swapping the slug in the path used to give. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj3iCRvSP9sP7y7hxXVJbx
Logs and Query are gated by an organization feature flag, and their loaders redirect home when it is off, so carrying either across an organization switch sent the user through `/` instead of straight into the organization they picked. They now travel with an environment or project switch — both stay inside the organization whose flag let the user open the page — and an organization switch falls back to Tasks, the same shape the branch lists already use. A test scans the routes below an environment for the ones that redirect home and asserts they are exactly the pages the organization switch drops, so a third gated page cannot be added without updating the list. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj3iCRvSP9sP7y7hxXVJbx
The built-in queues dashboard is gated per organization, like Logs and Query, so it belongs in ORGANIZATION_SPECIFIC_PAGES rather than being left out of the portable pages entirely: an environment or project switch stays inside the organization whose flag let you open it. The manifest assertion that derives the gated pages from the route sources now reads both ways a loader turns you away — a redirect home and a 404 on the same shape of organization gate — so a future gated page still cannot slip in unnoticed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj3iCRvSP9sP7y7hxXVJbx
|
Preview Deployment
|
…oards The built-in metric dashboards all share one route, so the route manifest cannot notice a new one. Compare the declared dashboards/* portable pages against builtInDashboardList() instead, so adding a fourth dashboard without listing it fails the test rather than silently degrading to the dashboards index on a switch. Co-Authored-By: Claude <noreply@anthropic.com>
The page below the environment was sliced off the front of the pathname on a bare startsWith, so an environment slug that strictly prefixes another — branch slugs are `<parent>-<branch>`, making `preview-feat` a prefix of `preview-feat-2` — yielded a garbled suffix that resolved to no page. The switcher hooks can hit this mid-navigation, where the pathname comes from the pending location but the environment path still comes from the current match. Co-Authored-By: Claude <noreply@anthropic.com>
Truncating every resource page to its list is right for a resource an environment issued an id for, but the last segment of a task, agent, prompt, playground or model page is a name that comes from the user's code or the model catalog, so it names the same thing in every environment of the project. An environment switch now keeps that name, as swapping the slug used to; a project or organization switch still truncates, since the name need not exist over there. The leak assertion is split rather than relaxed: pages addressed by an id must still resolve with the id gone, for all three switches, and the slug-addressed ones must come back whole from an environment switch. Co-Authored-By: Claude <noreply@anthropic.com>
A custom dashboard is looked up by its friendly id scoped to the organization rather than the environment, so every environment of the project opens the same dashboard at the same address. Truncating `dashboards/custom/<id>` to the dashboard list on an environment switch lost the user's place for no reason; it now travels like the slug-addressed pages, under the same guard on the trailing segment, while a project or organization switch still truncates it. Integrations is gated on the caller's role rather than on an organization feature flag, and a role differs between organizations, so carrying that page across an organization switch could land on the permission panel where the switch used to land on Tasks. It joins the pages an organization switch drops, and the manifest-derived check now reads a role gate on a loader as well as a feature flag, so a future one cannot slip in unnoticed. Co-Authored-By: Claude <noreply@anthropic.com>
ericallam
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Eric Allam · Slack thread
Before: you're on the API keys page in project X, you switch to project Y in the sidebar, and you land on project Y's Tasks page. Same for switching organization. Every switch threw away the page you were looking at.
After: you land on project Y's API keys page. Switching organization does the same thing, one project down. Pages that name a single thing — a run, a batch, a queue, a schedule, a deploy, a session, an error group — can't exist in another project, so those take you to the matching list page instead (a run page takes you to Runs).
The environment is still chosen exactly as it is today: nothing tries to guess it in the browser.
Testing
apps/webapp/app/utils/pageSwitching.test.ts(35 tests). It reads the compiled Remix route manifest, so the portable-page list can't silently drift from the routes://, absolute URL,.., percent-encoded traversal,javascript:, unknown page — each falls back to Tasks rather than being sanitised into somethingpnpm run typecheck --filter webapppasses.app/utils/pass (15 files, 150 tests).Changelog
Switching project or organization in the sidebar keeps you on the same page instead of sending you back to Tasks. Pages for a specific run, deploy or other single item open the matching list instead.
How
The switcher links already pointed at
/orgs/:org/projects/:projectand/orgs/:org, whose_indexloaders resolve the best environment (and, for the organization, the best project) and redirect. So the page travels as a search param on those links, and each loader appends it to the path it already builds:app/utils/pageSwitching.ts— one pure module.environmentPortablePage(suffix)andprojectPortablePage(suffix)walk up the suffix until they find an entry in an allowlist of portable pages, and answer with the environment root if they find none. The result is therefore always a literal from that closed set, which is what makes it safe to concatenate into a redirect target; there is no regex sanitising. The allowlist is built from the landing pages already listed indeeplinkPages.tsplus the handful of nested pages that file doesn't know about, so this isn't a new URL-shape table.app/hooks/useEnvironmentSwitcher.ts—usePageSwitcher()derives the current page by slicing the environment layout route match's pathname off the current pathname, so there's no route table on the client either. The query string and hash are dropped on a project or organization switch, since filters encode task slugs and ids scoped to the project you're leaving._indexloaders re-validate the page through the same function before using it.Two things worth a look:
runs/:runParam,deployments/:deploymentParamandschedules/:scheduleParam; the other 16 id-bearing routes carried their id straight into the new environment (e.g.queues/:queueParam,batches/:batchParam,errors/:fingerprint,sessions/:sessionParam). All three switchers now share one truncation, and the test asserts it covers every such route in the manifest.envParam— so an environment switch keeps them, exactly as swapping the slug did before. A project or organization switch still falls back to Tasks, since the project you land in may have no preview branches. A test locks the environment half: every id-free page below an environment has to survive an environment switch.Screenshots
n/a — no visual change; only where the switcher links point.
💯