Skip to content

Commit e941365

Browse files
authored
RSC: react-server condition. Poisoned imports (#8948)
1 parent 3588ec0 commit e941365

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

packages/vite/src/rscBuild.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ export async function rscBuild(viteConfigPath: string) {
3636
(id) => serverEntryFileSet.add(id)
3737
),
3838
],
39-
// ssr: {
40-
// // FIXME Without this, waku/router isn't considered to have client
41-
// // entries, and "No client entry" error occurs.
42-
// // Unless we fix this, RSC-capable packages aren't supported.
43-
// // This also seems to cause problems with pnpm.
44-
// // noExternal: ['@redwoodjs/web', '@redwoodjs/router'],
45-
// },
39+
ssr: {
40+
noExternal: /^(?!node:)/,
41+
// TODO (RSC): Figure out what the `external` list should be. Right
42+
// now it's just copied from waku
43+
external: ['react', 'minimatch'],
44+
},
45+
resolve: {
46+
conditions: ['react-server'],
47+
},
4648
build: {
4749
manifest: 'rsc-build-manifest.json',
4850
write: false,
@@ -53,6 +55,9 @@ export async function rscBuild(viteConfigPath: string) {
5355
},
5456
},
5557
},
58+
legacy: {
59+
buildSsrCjsExternalHeuristics: true,
60+
},
5661
})
5762

5863
const clientEntryFiles = Object.fromEntries(

packages/vite/src/waku-lib/build-server.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,19 @@ export async function serverBuild(
3333
// ...configFileConfig,
3434
root: rwPaths.web.base,
3535
ssr: {
36-
noExternal: ['..'],
36+
noExternal: true,
37+
// TODO (RSC): The code below is pretty much what waku does, but I don't
38+
// understand it
39+
// noExternal: Object.values(clientEntryFiles).map((fname) => {
40+
// return path
41+
// .relative(path.join(rwPaths.web.base, 'node_modules'), fname)
42+
// .split('/')[0]
43+
// }),
3744
},
3845
plugins: [react()],
46+
resolve: {
47+
conditions: ['react-server'],
48+
},
3949
build: {
4050
ssr: true,
4151
ssrEmitAssets: true,

packages/vite/src/waku-lib/rsc-handler-worker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ const vitePromise = createServer({
152152
parentPort.postMessage(mesg)
153153
}),
154154
],
155+
resolve: {
156+
conditions: ['react-server'],
157+
},
155158
ssr: {
156-
// FIXME Without this, "use client" directive in waku/router/client
157-
// is ignored, and some errors occur.
158-
// Unless we fix this, RSC-capable packages aren't supported.
159-
// This also seems to cause problems with pnpm.
160-
noExternal: ['waku'],
159+
noExternal: /^(?!node:)/,
160+
// TODO (RSC): Figure out what the `external` list should be. Right
161+
// now it's just copied from waku
162+
external: ['react', 'minimatch', 'react-server-dom-webpack'],
161163
},
162164
appType: 'custom',
163165
})

0 commit comments

Comments
 (0)