[start] Incomplete basepath handling #4888
Send to my agentNote
The solution was to also set the base property in the vite config. I'll leave the issue open until this is documented.
Which project does this relate to?#
Start
Describe the bug#
When setting a basepath, every single resource needs to be prefixed with that basepath, or the app will break when put behind a proxy that only routes requests to that basepath to the app.
We have a very prod-like setup for local dev, so we need basepath handling to work fully for the dev server, or it breaks, since we only route requests to /app over to our dashboard application.
Here are my findings of things that break so far when setting basepath to /app:
- Without creating a client entry point,
/~start/default-client-entryis requested - If I create a client entry point, all the imports from client.tsx are requested without the basepath.
/@vite/client/node_modules/.vite/deps/solid-js_web.js?v=e4a53580/@fs/Users/jakst/project/node_modules/.pnpm/@tanstack+solid-start@1.130.15_solid-js@1.9.7_vite-plugin-solid@2.11.8_solid-js@1.9.7_v_2de64603fd083e50c9f52c16fb1b9292/node_modules/@tanstack/solid-start/dist/esm/client.js?v=e4a53580/src/router.tsx
Another thing that is a bit weird with basepath handling is that if I create routes/api.hello.tsx as a serverFileRoute, it does not get the basepath applied. So all serverFileRoutes have to be put in a folder with the basepath name, while the regular page routes have the basepath applied automatically.
Your Example Website or App#
https://codesandbox.io/p/devbox/jovial-dawn-63xwyj
Steps to Reproduce the Bug or Issue#
I couldn't get the codesandbox working, but it's fairly straight forward:
- Create a new tanstack start project
- Add
basepath: '/app'to the options inrouter.tsx - Open the app in your browser and notice that
/~start/default-client-entryis requested without the basepath - Add a default client entry point
- Restart the dev server
- Go to the app in your browser again
- Notice that the browser requests a bunch of files that are not prefixed with
/app
Expected behavior#
I expect all files requested from the dev server to be prefixed with /app.
Screenshots or Videos#
No response
Platform#
- Router / Start Version: 1.130.15
- OS: MacOS
- Browser: Chrome
- Browser Version: 138
- Bundler: vite
- Bundler Version: 7.0.6
Additional context#
No response
jakst(GitHub profile, opens in a new tab) changed the title
SeanCassiere added labelsstart
You may want to set the
basein your vite config as well.router/e2e/react-start/custom-basepath/vite.config.ts
Lines 5 to 11 in 0a3bb24
export default defineConfig({ base: '/custom/basepath', server: { port: 3000, }, plugins: [ tsConfigPaths({
Of course... 🤦♂️
So consider this a request to document that it needs to change in both places instead 😅 I didn't find anything about basepath handling in the documentation.
And thanks a lot!
schiller-manuel(GitHub profile, opens in a new tab) added labelsdocumentation
Would it be okay to proceed with the documentation process?
we need to think about the basepath handling some more, there are scenarios (Dev vs prod) that are not handled correctly. until then, we leave this open. no need to document the current state really as we need to fix a few things
I was thinking about using
basepathfor localization handling and asgetRouteris a function my thoughts were that it might be possible to set it dynamically ingetRouterinto:- context
- basepath
While still be able to break-out of basepath in
server.tslike thisimport handler from "@tanstack/react-start/server-entry"; export default { fetch(request: Request) { if (request.url.endsWith("/robots.txt")) { return new Response("User-agent: *\nAllow: /\n\n", { headers: { "Content-Type": "text/plain" }, }); } return handler.fetch(request); }, };So this way I could get best of both worlds:
- dynamically set
basepathbased on request and have my linking system have zero knowledge about current locale because every link has it - still have ability to breakout for service routes
The problem is that without this scheme I need to have locale at all times available within some deep component to pass it to
linkOptions/Link.birkskyum(GitHub profile, opens in a new tab) added labelspackage: solid-start
birkskyum(GitHub profile, opens in a new tab) removed labelspackage: solid-start
Anything further needed here?
Anything further needed here?
Yes, the documentation work is still missing.
I reproduced the original Solid Start configuration on current
main. With onlycreateRouter({ basepath: '/custom/basepath' }), the mounted URL renders the not-found page and Vite's dev entry and styles are still requested from root paths. Adding the matching Vitebasemakes the application render with those resources under/custom/basepath/.#6792 subsequently added support for intentionally different Vite and Router bases. Its Chromium suite passes in both development and production on current
mainI think we need Start documentation to explain that Vite
baseowns asset URLs, while Start'srouter.basepathowns application routes, with examples for matching and split bases. Do you mind writing up an PR for it?whizzkid1452(GitHub profile, opens in a new tab) linked this to #7882
Sign in to join this conversation.
You may want to set the
basein your vite config as well.https://github.com/TanStack/router/blob/0a3bb242afb7bc2c0c57b90b6b98ef858003cae6/e2e/react-start/custom-basepath/vite.config.ts#L5-L11