With the Rsbuild plugin, routes whose only option is server stay in the client route tree, so the route file is bundled for the client. The Vite plugin prunes them.
Repro#
import '@tanstack/react-start/server-only'
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/api/hook')({
server: { handlers: { GET: () => new Response('ok') } },
})
tanstackStart({ importProtection: { behavior: 'error' } })
Run rsbuild build and vite build.
Expected#
Both builds pass and /api/hook is not in the client bundle.
Actual#
Vite passes. Rsbuild fails with [import-protection] Import denied in client environment … Importer: src/routes/api/hook.ts:1:9, traced through src/routeTree.gen.ts. Without the marker it builds, but the client bundle contains an empty createFileRoute('/api/hook')({}).
Possible fix#
Vite gives the client a pruned tree via clientTreePlugin + pruneServerOnlySubtrees (vite/start-router-plugin/plugin.ts#L92-L144). rsbuild/start-router-plugin.ts has no equivalent. A client-environment api.transform on the route tree, like the server-environment one in #8291, would cover it.
Workaround#
Move the marker into a *.server.ts module that the handler imports.
Versions#
@tanstack/react-start 1.168.59 (start-plugin-core 1.171.48, same on main @ 41ebd28), @rsbuild/core 2.2.10, Vite 8.3.1, Node 24.16.