Skip to content
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

RSC: react-server condition. Poisoned imports #8948

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/vite/src/rscBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ export async function rscBuild(viteConfigPath: string) {
(id) => serverEntryFileSet.add(id)
),
],
// ssr: {
// // FIXME Without this, waku/router isn't considered to have client
// // entries, and "No client entry" error occurs.
// // Unless we fix this, RSC-capable packages aren't supported.
// // This also seems to cause problems with pnpm.
// // noExternal: ['@redwoodjs/web', '@redwoodjs/router'],
// },
ssr: {
noExternal: /^(?!node:)/,
// TODO (RSC): Figure out what the `external` list should be. Right
// now it's just copied from waku
external: ['react', 'minimatch'],
},
resolve: {
conditions: ['react-server'],
},
build: {
manifest: 'rsc-build-manifest.json',
write: false,
Expand All @@ -53,6 +55,9 @@ export async function rscBuild(viteConfigPath: string) {
},
},
},
legacy: {
buildSsrCjsExternalHeuristics: true,
},
})

const clientEntryFiles = Object.fromEntries(
Expand Down
12 changes: 11 additions & 1 deletion packages/vite/src/waku-lib/build-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ export async function serverBuild(
// ...configFileConfig,
root: rwPaths.web.base,
ssr: {
noExternal: ['..'],
noExternal: true,
// TODO (RSC): The code below is pretty much what waku does, but I don't
// understand it
// noExternal: Object.values(clientEntryFiles).map((fname) => {
// return path
// .relative(path.join(rwPaths.web.base, 'node_modules'), fname)
// .split('/')[0]
// }),
},
plugins: [react()],
resolve: {
conditions: ['react-server'],
},
build: {
ssr: true,
ssrEmitAssets: true,
Expand Down
12 changes: 7 additions & 5 deletions packages/vite/src/waku-lib/rsc-handler-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ const vitePromise = createServer({
parentPort.postMessage(mesg)
}),
],
resolve: {
conditions: ['react-server'],
},
ssr: {
// FIXME Without this, "use client" directive in waku/router/client
// is ignored, and some errors occur.
// Unless we fix this, RSC-capable packages aren't supported.
// This also seems to cause problems with pnpm.
noExternal: ['waku'],
noExternal: /^(?!node:)/,
// TODO (RSC): Figure out what the `external` list should be. Right
// now it's just copied from waku
external: ['react', 'minimatch', 'react-server-dom-webpack'],
},
appType: 'custom',
})
Expand Down
Loading