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.
A remote's public SSR container is compiled as a server environment, so it kept createServerOnlyFn bodies, createIsomorphicFn().server() and createMiddleware().server(). Run TanStack Start's own StartCompiler, as a client compile without server functions, over the container's modules (except TanStack's own packages) before Start's server compile, and drop its cache on every (watch) build. Fail the build when Start's compiler cannot be loaded and a module uses those factories. The example remotes expose probes, and the example build asserts that only their own server output contains them. BREAKING CHANGE: While a host renders a remote on its server, the remote's exposed code now gets the browser versions of TanStack Start's server-only factories: createServerOnlyFn functions throw, createIsomorphicFn functions run their .client() implementation, and createMiddleware runs without .server() and .validator(). Exposed code that needs server behavior during the host's render must call a server function.
commit: |
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 public SSR container is compiled as a server environment, so it kept code that TanStack Start removes from the browser build:
createServerOnlyFnbodiescreateIsomorphicFn().server()implementationscreateMiddleware().server()handlersAll of these were published with the browser assets in
dist/client.Before this change, the example remotes' probes were confirmed to leak:
dist/client/assets/server-functions-*.jsdist/client/ssr/*.jsChanges
createContainerClientCompile(server-container.ts) runs TanStack Start's ownStartCompilerover the container's modules. It runs as a client compile (env: "client") and only for theServerOnlyFn,IsomorphicFnandMiddlewarekinds. It runs before Start's server compile, which turns server function handlers into RPC callers.createServerOnlyFnfunctions throw with Start's own message, isomorphic functions keep.client(), and middleware drops.server()and.validator(), all exactly as in the browser build.node_modules/@tanstack/), whose runtime the container needs on the server.@tanstack/start-plugin-core. If that fails and a module uses one of these factories, the build fails instead of publishing their server code.preplugin, placed before Start's compiler plugins, applied to themf_serverenvironment in build.pretransform onmf-server, registered after Start's transform so it runs first. It resolves throughctx.resolve, reads through the compiler'sinputFileSystem, and adds dependencies for watch.BREAKING CHANGE
While a host renders a remote on its server, the remote's exposed code now gets the browser versions of TanStack Start's server-only factories:
createServerOnlyFnfunctions throw.createIsomorphicFnfunctions run their.client()implementation.createMiddlewareruns without.server()and.validator().Exposed code that needs server behavior during the host's render must call a server function.
Tests
getRemoteGreeting. The example build asserts that the probe markers appear indist/serverand not indist/client. This test failed before the fix.test/release-contracts.test.mjs) covers:node_modulescompiled,@tanstack/skippedVerification
pnpm buildpnpm test:core(98/98)pnpm test:e2e(23/23)pnpm typecheckpnpm lintpnpm format:checkNotes
@tanstack/start-plugin-core/dist/esm/start-compiler/{compiler,config}.js, which Start does not export. If they move, the build fails rather than leaking..validator(): middleware loses.validator()too, because Start's client handler strips it. This PR accepts that behavior rather than changing it.PackagePathNotExportedwhen a module it compiles also has a top-levelcreateMiddleware()call. This happens in Start's ownssrenvironment too. The Rsbuild example therefore keeps its middleware inprobe-middleware.ts.