Skip to content

fix(studio): honor Vite BASE_URL as TanStack Router basepath#1168

Merged
hotlong merged 1 commit intomainfrom
copilot/fix-routing-issue-after-studio-migration
Apr 17, 2026
Merged

fix(studio): honor Vite BASE_URL as TanStack Router basepath#1168
hotlong merged 1 commit intomainfrom
copilot/fix-routing-issue-after-studio-migration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

When Studio is mounted under /_studio/ (CLI --ui, which sets VITE_BASE=/_studio/), TanStack Router matched the full pathname against root-defined routes and interpreted _studio as the $package param. All sub-routes 404'd (notFoundError on route "/$package"), e.g. /_studio/packages and /_studio/:package/objects/:name.

Changes

  • apps/studio/src/router.ts — derive basepath from import.meta.env.BASE_URL and pass it to createRouter. Normalizes to '/' for root deployments and strips the trailing slash for sub-path deployments ('/_studio/''/_studio'). Works transparently for CLI dev mode, Vercel, and standalone — no caller-side config required.
  • apps/studio/CHANGELOG.md — changelog entry.
// apps/studio/src/router.ts
function resolveBasepath(): string {
  const base = (import.meta.env.BASE_URL ?? '/').trim();
  if (!base || base === '/' || base === './') return '/';
  return base.endsWith('/') ? base.slice(0, -1) : base;
}

export const router = createRouter({
  routeTree,
  basepath: resolveBasepath(),
});

Verification

Reproduced and validated via Playwright against vite dev with VITE_BASE=/_studio/:

URL Before After
/_studio/packages "Not Found" (matched /$package="_studio"/packages) Package Manager
/_studio/api-console "Not Found" API Console
/_studio/ renders, but sub-routes broken renders, sub-routes resolve

The notFoundError console warning is gone.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-demo Ready Ready Preview, Comment Apr 17, 2026 2:11am
spec Ready Ready Preview, Comment Apr 17, 2026 2:11am

Request Review

@hotlong hotlong marked this pull request as ready for review April 17, 2026 02:14
Copilot AI review requested due to automatic review settings April 17, 2026 02:15
@hotlong hotlong merged commit bcf8e5b into main Apr 17, 2026
3 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Studio’s TanStack Router configuration so routing works correctly when the app is mounted under a sub-path (notably /_studio/ in CLI --ui mode), by aligning the router basepath with Vite’s runtime import.meta.env.BASE_URL.

Changes:

  • Derive and normalize TanStack Router basepath from import.meta.env.BASE_URL to prevent sub-path prefixes being treated as route params.
  • Add a Studio changelog entry describing the routing fix for sub-path deployments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/studio/src/router.ts Introduces resolveBasepath() and passes normalized basepath into createRouter() to support /_studio/ mounting.
apps/studio/CHANGELOG.md Adds an “Unreleased” patch note documenting the sub-path routing fix.

Comment thread apps/studio/CHANGELOG.md
Comment on lines +3 to +13
## Unreleased

### Patch Changes

- Fix TanStack Router basepath resolution when Studio is mounted under a sub-path
(e.g. `/_studio/` via the CLI `--ui` flag). Previously, routes such as
`/_studio/packages` or `/_studio/:package/objects/:name` failed to match —
the router treated the mount prefix as a `$package` route parameter, producing
"Not Found" errors. The router now derives `basepath` from Vite's
`import.meta.env.BASE_URL`, which works transparently for both root and
sub-path deployments.
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

apps/studio/CHANGELOG.md now contains multiple ## Unreleased sections (there are at least three). Adding another one at the top makes it harder to track changes and can break tooling or release processes that assume a single Unreleased section. Consider consolidating all Unreleased entries into a single top section, and convert the older Unreleased blocks into versioned releases (or remove them if they were historical artifacts).

Copilot uses AI. Check for mistakes.
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.

3 participants