Skip to content

Commit

Permalink
RSC: react-server condition. Poisoned imports (#8948)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jul 21, 2023
1 parent 3588ec0 commit e941365
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
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

0 comments on commit e941365

Please sign in to comment.