-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(start-rsbuild): compile node_modules for RSC directives #7540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
schiller-manuel
merged 4 commits into
TanStack:main
from
SyMind:rsbuild-rsc-node-modules
Jun 4, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/start-plugin-core': patch | ||
| --- | ||
|
|
||
| Fix Rsbuild RSC builds so client directives in packages under `node_modules` are compiled and detected correctly. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| node_modules | ||
| !src/node_modules/ | ||
| !src/node_modules/rsc-client-pkg/ | ||
| !src/node_modules/rsc-client-pkg/** | ||
| package-lock.json | ||
| yarn.lock | ||
|
|
||
| .DS_Store | ||
| .cache | ||
| .env | ||
| .vercel | ||
| .output | ||
|
|
||
| /build/ | ||
| /api/ | ||
| /server/build | ||
| /public/build | ||
| /dist/ | ||
| /dist-rsbuild-*/ | ||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ | ||
| port-*.txt |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .prettierrc |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "name": "tanstack-react-start-e2e-rsc-rsbuild", | ||
| "private": true, | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "rsbuild dev", | ||
| "dev:e2e": "rsbuild dev --port $PORT", | ||
| "build": "rsbuild build && tsc --noEmit", | ||
| "start": "node server.js", | ||
| "test:e2e-full": "pnpm build && sh -c 'rm -f \"port-${E2E_PORT_KEY:-$npm_package_name}.txt\" \"port-${E2E_PORT_KEY:-$npm_package_name}-external.txt\"' && playwright test --project=chromium" | ||
| }, | ||
| "nx": { | ||
| "metadata": { | ||
| "playwrightModes": [ | ||
| { | ||
| "toolchain": "rsbuild", | ||
| "mode": "ssr" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/react-router": "workspace:^", | ||
| "@tanstack/react-start": "workspace:^", | ||
| "react": "^19.0.0", | ||
| "react-dom": "^19.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.50.1", | ||
| "@rsbuild/core": "^2.0.8", | ||
| "@rsbuild/plugin-react": "^2.0.0", | ||
| "@tanstack/router-e2e-utils": "workspace:^", | ||
| "@types/node": "^22.10.2", | ||
| "@types/react": "^19.0.8", | ||
| "@types/react-dom": "^19.0.3", | ||
| "srvx": "^0.10.0", | ||
| "typescript": "^5.7.2" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import fs from 'node:fs' | ||
| import { defineConfig, devices } from '@playwright/test' | ||
| import { | ||
| getDummyServerPort, | ||
| getTestServerPort, | ||
| } from '@tanstack/router-e2e-utils' | ||
| import packageJson from './package.json' with { type: 'json' } | ||
|
|
||
| const e2ePortKey = process.env.E2E_PORT_KEY ?? packageJson.name | ||
| const distDir = process.env.E2E_DIST_DIR ?? 'dist' | ||
|
|
||
| if (process.env.TEST_WORKER_INDEX === undefined) { | ||
| for (const portFile of [ | ||
| `port-${e2ePortKey}.txt`, | ||
| `port-${e2ePortKey}-external.txt`, | ||
| ]) { | ||
| fs.rmSync(portFile, { force: true }) | ||
| } | ||
| } | ||
|
|
||
| const PORT = await getTestServerPort(e2ePortKey) | ||
| const EXTERNAL_PORT = await getDummyServerPort(e2ePortKey) | ||
| const baseURL = `http://localhost:${PORT}` | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './tests', | ||
| workers: 1, | ||
| reporter: [['line']], | ||
|
|
||
| globalSetup: './tests/setup/global.setup.ts', | ||
| globalTeardown: './tests/setup/global.teardown.ts', | ||
|
|
||
| use: { | ||
| baseURL, | ||
| }, | ||
|
|
||
| webServer: { | ||
| command: 'pnpm start', | ||
| url: baseURL, | ||
| reuseExistingServer: !process.env.CI, | ||
| stdout: 'pipe', | ||
| env: { | ||
| PORT: String(PORT), | ||
| E2E_DIST_DIR: distDir, | ||
| E2E_PORT_KEY: e2ePortKey, | ||
| EXTERNAL_SERVER_URL: `http://localhost:${EXTERNAL_PORT}`, | ||
| }, | ||
| }, | ||
|
|
||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { | ||
| ...devices['Desktop Chrome'], | ||
| }, | ||
| }, | ||
| ], | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { defineConfig } from '@rsbuild/core' | ||
| import { pluginReact } from '@rsbuild/plugin-react' | ||
| import { tanstackStart } from '@tanstack/react-start/plugin/rsbuild' | ||
|
|
||
| const outDir = process.env.E2E_DIST_DIR ?? 'dist' | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| pluginReact({ splitChunks: false }), | ||
| tanstackStart({ | ||
| rsc: { | ||
| enabled: true, | ||
| }, | ||
| }), | ||
| ], | ||
| output: { | ||
| distPath: { | ||
| root: outDir, | ||
| }, | ||
| }, | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
| import { spawn } from 'node:child_process' | ||
| import { pathToFileURL } from 'node:url' | ||
|
|
||
| const distDir = process.env.E2E_DIST_DIR || 'dist' | ||
|
|
||
| function resolveDistClientDir() { | ||
| return path.resolve(distDir, 'client') | ||
| } | ||
|
|
||
| function resolveDistServerEntryPath() { | ||
| const serverJsPath = path.resolve(distDir, 'server', 'server.js') | ||
| if (fs.existsSync(serverJsPath)) { | ||
| return serverJsPath | ||
| } | ||
|
|
||
| const indexJsPath = path.resolve(distDir, 'server', 'index.js') | ||
| if (fs.existsSync(indexJsPath)) { | ||
| return indexJsPath | ||
| } | ||
|
|
||
| return serverJsPath | ||
| } | ||
|
|
||
| export function resolveStartCommand() { | ||
| const distClientDir = resolveDistClientDir() | ||
| const distServerEntryPath = resolveDistServerEntryPath() | ||
| return `srvx --prod -s ${JSON.stringify(distClientDir)} ${JSON.stringify(distServerEntryPath)}` | ||
| } | ||
|
|
||
| export function start() { | ||
| const child = spawn( | ||
| 'srvx', | ||
| ['--prod', '-s', resolveDistClientDir(), resolveDistServerEntryPath()], | ||
| { | ||
| stdio: 'inherit', | ||
| shell: process.platform === 'win32', | ||
| }, | ||
| ) | ||
|
|
||
| child.on('exit', (code, signal) => { | ||
| if (signal) { | ||
| process.kill(process.pid, signal) | ||
| return | ||
| } | ||
|
|
||
| process.exit(code ?? 0) | ||
| }) | ||
| } | ||
|
|
||
| if ( | ||
| process.argv[1] && | ||
| import.meta.url === pathToFileURL(process.argv[1]).href | ||
| ) { | ||
| start() | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
e2e/react-start/rsc-rsbuild/src/node_modules/rsc-client-pkg/index.d.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
e2e/react-start/rsc-rsbuild/src/node_modules/rsc-client-pkg/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
e2e/react-start/rsc-rsbuild/src/node_modules/rsc-client-pkg/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* eslint-disable */ | ||
|
|
||
| // @ts-nocheck | ||
|
|
||
| // noinspection JSUnusedGlobalSymbols | ||
|
|
||
| // This file was automatically generated by TanStack Router. | ||
| // You should NOT make any changes in this file as it will be overwritten. | ||
| // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. | ||
|
|
||
| import { Route as rootRouteImport } from './routes/__root' | ||
| import { Route as RscNodeModuleClientRouteImport } from './routes/rsc-node-module-client' | ||
| import { Route as IndexRouteImport } from './routes/index' | ||
|
|
||
| const RscNodeModuleClientRoute = RscNodeModuleClientRouteImport.update({ | ||
| id: '/rsc-node-module-client', | ||
| path: '/rsc-node-module-client', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const IndexRoute = IndexRouteImport.update({ | ||
| id: '/', | ||
| path: '/', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
|
|
||
| export interface FileRoutesByFullPath { | ||
| '/': typeof IndexRoute | ||
| '/rsc-node-module-client': typeof RscNodeModuleClientRoute | ||
| } | ||
| export interface FileRoutesByTo { | ||
| '/': typeof IndexRoute | ||
| '/rsc-node-module-client': typeof RscNodeModuleClientRoute | ||
| } | ||
| export interface FileRoutesById { | ||
| __root__: typeof rootRouteImport | ||
| '/': typeof IndexRoute | ||
| '/rsc-node-module-client': typeof RscNodeModuleClientRoute | ||
| } | ||
| export interface FileRouteTypes { | ||
| fileRoutesByFullPath: FileRoutesByFullPath | ||
| fullPaths: '/' | '/rsc-node-module-client' | ||
| fileRoutesByTo: FileRoutesByTo | ||
| to: '/' | '/rsc-node-module-client' | ||
| id: '__root__' | '/' | '/rsc-node-module-client' | ||
| fileRoutesById: FileRoutesById | ||
| } | ||
| export interface RootRouteChildren { | ||
| IndexRoute: typeof IndexRoute | ||
| RscNodeModuleClientRoute: typeof RscNodeModuleClientRoute | ||
| } | ||
|
|
||
| declare module '@tanstack/react-router' { | ||
| interface FileRoutesByPath { | ||
| '/rsc-node-module-client': { | ||
| id: '/rsc-node-module-client' | ||
| path: '/rsc-node-module-client' | ||
| fullPath: '/rsc-node-module-client' | ||
| preLoaderRoute: typeof RscNodeModuleClientRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/': { | ||
| id: '/' | ||
| path: '/' | ||
| fullPath: '/' | ||
| preLoaderRoute: typeof IndexRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const rootRouteChildren: RootRouteChildren = { | ||
| IndexRoute: IndexRoute, | ||
| RscNodeModuleClientRoute: RscNodeModuleClientRoute, | ||
| } | ||
| export const routeTree = rootRouteImport | ||
| ._addFileChildren(rootRouteChildren) | ||
| ._addFileTypes<FileRouteTypes>() | ||
|
|
||
| import type { getRouter } from './router.tsx' | ||
| import type { createStart } from '@tanstack/react-start' | ||
| declare module '@tanstack/react-start' { | ||
| interface Register { | ||
| ssr: true | ||
| router: Awaited<ReturnType<typeof getRouter>> | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { createRouter } from '@tanstack/react-router' | ||
| import { routeTree } from './routeTree.gen' | ||
|
|
||
| export function getRouter() { | ||
| return createRouter({ | ||
| routeTree, | ||
| scrollRestoration: true, | ||
| defaultPreload: 'intent', | ||
| }) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { | ||
| HeadContent, | ||
| Outlet, | ||
| Scripts, | ||
| createRootRoute, | ||
| useHydrated, | ||
| } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createRootRoute({ | ||
| head: () => ({ | ||
| meta: [ | ||
| { charSet: 'utf-8' }, | ||
| { name: 'viewport', content: 'width=device-width, initial-scale=1' }, | ||
| { title: 'Rsbuild RSC test' }, | ||
| ], | ||
| }), | ||
| component: RootComponent, | ||
| }) | ||
|
|
||
| function RootComponent() { | ||
| const hydrated = useHydrated() | ||
|
|
||
| return ( | ||
| <html> | ||
| <head> | ||
| <HeadContent /> | ||
| </head> | ||
| <body> | ||
| <span data-testid="app-hydrated" style={{ display: 'none' }}> | ||
| {hydrated ? 'hydrated' : 'hydrating'} | ||
| </span> | ||
| <Outlet /> | ||
| <Scripts /> | ||
| </body> | ||
| </html> | ||
| ) | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail fast when no server build artifact exists.
If neither
dist/server/server.jsnordist/server/index.jsexists, returningserverJsPathhides the root cause and fails later insidesrvx. Throw an explicit error here.Proposed fix
function resolveDistServerEntryPath() { const serverJsPath = path.resolve(distDir, 'server', 'server.js') if (fs.existsSync(serverJsPath)) { return serverJsPath } const indexJsPath = path.resolve(distDir, 'server', 'index.js') if (fs.existsSync(indexJsPath)) { return indexJsPath } - return serverJsPath + throw new Error( + `Server entry not found. Looked for "${serverJsPath}" and "${indexJsPath}". Did you run the build first?`, + ) }🤖 Prompt for AI Agents