Repository navigation
Conversation
A remote's public SSR container is compiled as a server environment, so TanStack Start's import protection does not apply to it. Fail the build (warn in Rsbuild dev) when a *.server.* app module, or one importing @tanstack/<framework>-start/server or /server-only, reaches the container after Start's compiler has run. Imports only server function handlers use are removed by then and still pass.
commit: |
6 tasks done
This branch has not been deployed
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.
Problem
A remote's SSR container (
remoteEntry.ssr.jsfor Vite,remoteEntry.ssr.cjsfor Rsbuild, plus their chunks) is written todist/client, so it is published with the browser assets. It is compiled as a server environment, though, so TanStack Start's import protection for the browser does not apply to it. A*.server.*module, or one that imports@tanstack/<framework>-start/serveror/server-only, could end up in the public container. With it went whatever server-only code it held, such as secrets or internal endpoints.Changes
createServerOnlyModuleCheck(server-container.ts) checks each module that reaches the container after Start's compiler has run. It flags an app module that:*.server.*file, or@tanstack/{react,solid,vue}-start/serveror/server-only.It ignores:
node_modulesimport typeOn a match, the build fails. Rsbuild dev only warns (
api.logger.warn).The Vite and Rsbuild adapters run the check in their existing server container transforms.
Imports that only
createServerFnhandlers use are gone by the time the check runs, so they still pass.README: the "SSR federation" bullet no longer suggests the container holds everything. A new paragraph says what stays out and how to call server-only code.
The example remotes now read their greeting from
greeting.server.ts, which only a server function handler uses.Tests
test/release-contracts.test.mjs) covers:*.server.*files and server/server-only imports thrownode_modulesmodules passimport type, comments and strings passgreeting.server.tsdirectly fails to build.Verification
pnpm buildpnpm test:core(95/95)pnpm test:e2e(23/23)pnpm typecheckpnpm lintpnpm format:checkNotes
*.server.*module or/server-onlyinside acreateServerOnlyFn,createIsomorphicFn().server()orcreateMiddleware().server()body. Those bodies are not removed from the container yet. The follow-up PR compiles them away. Ideally both ship in the same release.*.server.*module that is itself listed inexposes.