Skip to content

feat(webapp): stay on the same page when switching project or organization - #4585

Merged
ericallam merged 8 commits into
mainfrom
claude/preserve-page-on-project-switch
Aug 12, 2026
Merged

feat(webapp): stay on the same page when switching project or organization#4585
ericallam merged 8 commits into
mainfrom
claude/preserve-page-on-project-switch

Conversation

@claude

@claude claude Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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

  • New 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:
    • every environment page that names no resource survives an environment switch — the same pages the old slug swap kept
    • the two branch lists are the only pages an environment switch keeps and a project switch drops
    • the pages gated per organization — Logs, Query and the queue metrics dashboard — travel with an environment or project switch but not an organization switch, and that list is derived from the route sources so a new gated page cannot be missed
    • every portable page points at a route that exists
    • every one of the 19 environment routes that takes a resource id truncates to a list page, with the id gone
    • portable pages resolve to themselves, so switching twice lands in the same place
    • every rejection case: leading slash, //, absolute URL, .., percent-encoded traversal, javascript:, unknown page — each falls back to Tasks rather than being sanitised into something
  • Manual: switch project and organization from API keys, project settings, a run page, and a queue page.
  • pnpm run typecheck --filter webapp passes.
  • The rest of the webapp suite needs Docker for testcontainers, which wasn't available here; all colocated pure unit tests under 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/:project and /orgs/:org, whose _index loaders 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) and projectPortablePage(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 in deeplinkPages.ts plus the handful of nested pages that file doesn't know about, so this isn't a new URL-shape table.
  • app/hooks/useEnvironmentSwitcher.tsusePageSwitcher() 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.
  • Both _index loaders re-validate the page through the same function before using it.

Two things worth a look:

  • The environment switcher's truncation gap is fixed as a side effect. It had a hand-written switch covering runs/:runParam, deployments/:deploymentParam and schedules/: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.
  • Portability turned out to be two properties, not one. Preview branches and dev branches render under any environment slug of their project — both loaders pass a hardcoded environment type and the project slug and never read 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.

💯

…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.
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 00174eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@claude

claude Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review


Generated by Claude Code

@claude
claude Bot marked this pull request as ready for review August 12, 2026 10:54
devin-ai-integration[bot]

This comment was marked as resolved.

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
devin-ai-integration[bot]

This comment was marked as resolved.

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
devin-ai-integration[bot]

This comment was marked as resolved.

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
@trigger-dot-bot

trigger-dot-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

Preview Deployment

Status Preview Commit Updated
⚪ Removed ed4461d Aug 12, 14:40 UTC

…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>
devin-ai-integration[bot]

This comment was marked as resolved.

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>
devin-ai-integration[bot]

This comment was marked as resolved.

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>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 3 new potential issues.

Open in Devin Review

Comment thread apps/webapp/app/utils/pageSwitching.ts
Comment thread apps/webapp/app/hooks/useEnvironmentSwitcher.ts
Comment thread apps/webapp/app/utils/pageSwitching.ts Outdated
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>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment thread apps/webapp/app/utils/pageSwitching.ts
@ericallam
ericallam merged commit 442702e into main Aug 12, 2026
49 of 50 checks passed
@ericallam
ericallam deleted the claude/preserve-page-on-project-switch branch August 12, 2026 14:35
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
ericallam pushed a commit that referenced this pull request Aug 13, 2026
## Summary
4 new features, 24 improvements, 10 bug fixes.

## Highlights

- Allow `trigger deploy` to authenticate with an environment API key
from `TRIGGER_ACCESS_TOKEN`.
([#4561](#4561))

## Improvements
- Chat in the browser now reconnects when the connection drops mid-turn,
instead of leaving the reply stuck as if it were still generating.
Reports can be fetched as structured data with the `json` format, and
the shortest report period is now one minute (`1m`, `30m`, `1h`, `7d`).
The `mint-token` command's help is clearer too: a token minted without
`--cap` is read-only, and `--ttl` shows the correct maximum lifetime of
7 days.
([#4418](#4418))
- The dev environment onboarding now tracks real progress. After you run
`init`, the setup checklist marks your project as initialized, and it
updates live as your dev server connects and your tasks register. The
blank state also adds a "Copy AI agent prompt" button that copies a
ready-to-paste setup prompt (pre-filled with your project reference) for
Claude Code, Cursor, or any coding agent.
([#4563](#4563))
  
The `init` scaffold now imports from `@trigger.dev/sdk` instead of the
deprecated `@trigger.dev/sdk/v3` subpath.
- Deployed images now ship dependencies and bundled task code as
separate layers. Repeat deploys with unchanged dependencies typically
push and pull far less data, making deploys and worker image pulls
faster.
([#4551](#4551))
- The current-worker API now reports each task's queue, so you can see
which tasks write to a given queue.
([#4525](#4525))
- Watch-mode chat streams now survive quiet windows and page reloads,
and a reply cut off by a lost connection shows an error instead of
appearing finished. Aborting a resumed subscription only closes your
local stream — call `stopGeneration(chatId)` or pass `stopOnAbort: true`
to stop the run. Also fixed a race where quickly restarting a stream
could break stop and reconnect, and stopping a chat now hands it back to
your other tabs instead of leaving them read-only.
([#4516](#4516))

## Server changes

These changes affect the self-hosted Docker image and Trigger.dev Cloud:

- The dashboard agent now has a monthly message allowance and plan-based
limits on watches. Queries stay read-only with clearer errors when busy,
and messages with unusual characters no longer fail to send.
([#4516](#4516))
- Meet the dashboard agent: a chat in every environment that answers
questions about your runs, queues, errors and health with real data and
links, replacing Ask AI everywhere it used to appear. Investigate a
failed run, an error, a backed-up queue or a run that hasn't started to
get a worked-through answer — what happened, why, and how to fix it,
with every claim linked to the runs, errors and deploys behind it. It
reads your data read-only, works on preview and dev branches with that
branch's own data, and reads the same everywhere — dashboard, terminal,
editor. A very long chat keeps working: the agent summarises the earlier
part and carries on.
  
**Watch…** on a run, queue, error or the health report tells you when
things change: a run finishes, a queue clears or grows past a number you
pick, an error comes back, an environment recovers. The answer arrives
in the chat and, if you want, by email, Slack or webhook — and the agent
can look into bad news on its own. A watch reaches you on any browser
you sign in from, without opening the chat first.
  
A sample of conversations is scored automatically so the agent keeps
getting better; only the score and a one-line summary are kept, never
your messages, data or code, and we can switch it off for your
organization on request. Ask the agent instead of the Docs buttons in
page headers — they stay there when the agent isn't available to you.
Separately, a queue's wait times, peak depth, throughput and throttling
can now be read from the API.
([#4418](#4418))
- Add backend support for delaying cron schedules within a specified
window with a minimum of 60 seconds.
([#4566](#4566))
- Reduced recurring background database load from the billing-limit
recovery check, so paused environments are reconciled with less
overhead.
([#4590](#4590))
- Validating a schedule when deploying or updating a schedule now does
less work on projects with many preview branches, so those operations
stay fast as branches accumulate.
([#4598](#4598))
- Project pages now load faster for projects with a large number of
preview branches, by no longer loading archived branch environments that
aren't shown.
([#4595](#4595))
- Database queries that filter on a list of values now reuse cached
query plans more consistently, instead of forcing the database to
re-plan whenever the list length changes.
([#4480](#4480))
- Routine cleanup of old dashboard agent data now runs on its own
schedule.
([#4599](#4599))
- Database connection metrics are now reported for every configured
database connection instead of only the primary one, and stay accurate
regardless of connection type.
([#4541](#4541))
- Deployment-related API endpoints now draw from their own generous rate
limit budget, configurable via the `DEPLOYMENT_RATE_LIMIT_*` environment
variables, so runtime API traffic no longer competes with deployments
for the same per-environment budget.
([#4565](#4565))
- Deleting or editing a secret environment variable is now fast and no
longer slows down as a project accumulates variables.
([#4555](#4555))
- Speed up personal access token lookups by indexing them on their owner
([#4588](#4588))
- Switching project or organization in the sidebar now 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.
([#4585](#4585))
- Reduced database load when loading the dashboard by removing an unused
organization member count that was being calculated on every page
navigation.
([#4587](#4587))
- The environment variables page now loads a page at a time, keeping it
fast for projects with a large number of variables. Search matches
variable names across every page.
([#4597](#4597))
- Groundwork for an alternative database connection driver, gated behind
configuration and disabled by default, so there is no change to default
behavior.
([#4539](#4539))
- Deleting an alert channel is now fast and no longer slows down as a
project builds up alert history.
([#4554](#4554))
- Reduced internal overhead on the API under high load.
([#4532](#4532))
- Out-of-date upgrade prompts no longer appear in the dashboard: the
"V4" badges and the notices saying preview branches and the queues table
need V4 have been removed. The side menu still warns you when a project
is on v3, with updated wording and a link to the v4 upgrade guide.
([#4589](#4589))
- Make background worker registration cheaper for projects with many
scheduled tasks by scoping declarative schedule reconciliation to the
current environment and dropping redundant schedule lookups.
([#4577](#4577))
- Speed up setting and importing environment variables for projects with
many variables.
([#4579](#4579))
- Loading the deployments list is now faster, especially when filtering
by deployment status on projects with many deployments.
([#4591](#4591))
- Fixed the billing limits page timing out for organizations with many
preview branches, especially while a spend limit was being enforced. The
page now loads quickly, so you can raise or resolve your limit without
delay. ([#4594](#4594))
- Fix the Concurrency page showing the plan's default concurrency for
the dev environment instead of the environment's actual limit.
([#4596](#4596))
- Creating an organization sometimes left you back on the creation form
even though the organization had already been created, so clicking
Create again made a duplicate. Creating an organization now completes
and takes you to your new organization.
([#4530](#4530))
- Ensure creating a project completes instead of returning to its
creation form after a navigation error.
([#4584](#4584))
- Renaming a project now keeps you on the project settings page and
tells you what happened, instead of silently moving you to the tasks
page or clearing the form with no explanation.
([#4601](#4601))
- Fixed support threads showing no account details for some customers,
so the team can see your plan, organizations and projects when you get
in touch.
([#4575](#4575))
- In the light theme, the Format, Clear and Copy buttons on the query
editor no longer blend into the query text behind them.
([#4592](#4592))
- The health report now says start latency is "unknown" when there is no
data for it, instead of showing a healthy-looking 0ms
([#4544](#4544))
- Realtime streams written inside a chat session run now use the same
backend as the session itself, and runs are no longer created against a
backend that cannot serve them.
([#4564](#4564))
- The grouped "watch updates" notification now shows the total number of
results waiting, instead of only the most recent batch's count.
([#4525](#4525))

<details>
<summary>Raw changeset output</summary>

# Releases
## @trigger.dev/build@4.5.11

### Patch Changes

- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
## trigger.dev@4.5.11

### Patch Changes

- Chat in the browser now reconnects when the connection drops mid-turn,
instead of leaving the reply stuck as if it were still generating.
Reports can be fetched as structured data with the `json` format, and
the shortest report period is now one minute (`1m`, `30m`, `1h`, `7d`).
The `mint-token` command's help is clearer too: a token minted without
`--cap` is read-only, and `--ttl` shows the correct maximum lifetime of
7 days.
([#4418](#4418))
- Allow `trigger deploy` to authenticate with an environment API key
from `TRIGGER_ACCESS_TOKEN`.
([#4561](#4561))
- The dev environment onboarding now tracks real progress. After you run
`init`, the setup checklist marks your project as initialized, and it
updates live as your dev server connects and your tasks register. The
blank state also adds a "Copy AI agent prompt" button that copies a
ready-to-paste setup prompt (pre-filled with your project reference) for
Claude Code, Cursor, or any coding agent.
([#4563](#4563))

The `init` scaffold now imports from `@trigger.dev/sdk` instead of the
deprecated `@trigger.dev/sdk/v3` subpath.

- Deployed images now ship dependencies and bundled task code as
separate layers. Repeat deploys with unchanged dependencies typically
push and pull far less data, making deploys and worker image pulls
faster.
([#4551](#4551))
- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
  - `@trigger.dev/build@4.5.11`
  - `@trigger.dev/schema-to-json@4.5.11`
## @trigger.dev/core@4.5.11

### Patch Changes

- Chat in the browser now reconnects when the connection drops mid-turn,
instead of leaving the reply stuck as if it were still generating.
Reports can be fetched as structured data with the `json` format, and
the shortest report period is now one minute (`1m`, `30m`, `1h`, `7d`).
The `mint-token` command's help is clearer too: a token minted without
`--cap` is read-only, and `--ttl` shows the correct maximum lifetime of
7 days.
([#4418](#4418))
- The current-worker API now reports each task's queue, so you can see
which tasks write to a given queue.
([#4525](#4525))
## @trigger.dev/python@4.5.11

### Patch Changes

- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
  - `@trigger.dev/sdk@4.5.11`
  - `@trigger.dev/build@4.5.11`
## @trigger.dev/react-hooks@4.5.11

### Patch Changes

- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
## @trigger.dev/redis-worker@4.5.11

### Patch Changes

- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
## @trigger.dev/rsc@4.5.11

### Patch Changes

- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
## @trigger.dev/schema-to-json@4.5.11

### Patch Changes

- Updated dependencies:
  - `@trigger.dev/core@4.5.11`
## @trigger.dev/sdk@4.5.11

### Patch Changes

- Chat in the browser now reconnects when the connection drops mid-turn,
instead of leaving the reply stuck as if it were still generating.
Reports can be fetched as structured data with the `json` format, and
the shortest report period is now one minute (`1m`, `30m`, `1h`, `7d`).
The `mint-token` command's help is clearer too: a token minted without
`--cap` is read-only, and `--ttl` shows the correct maximum lifetime of
7 days.
([#4418](#4418))
- Watch-mode chat streams now survive quiet windows and page reloads,
and a reply cut off by a lost connection shows an error instead of
appearing finished. Aborting a resumed subscription only closes your
local stream — call `stopGeneration(chatId)` or pass `stopOnAbort: true`
to stop the run. Also fixed a race where quickly restarting a stream
could break stop and reconnect, and stopping a chat now hands it back to
your other tabs instead of leaving them read-only.
([#4516](#4516))
- Updated dependencies:
  - `@trigger.dev/core@4.5.11`

</details>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants