Skip to content

Commit 9ac5ab2

Browse files
authored
RSC: Fix noExternal rule for server build (#8961)
1 parent 9a552c6 commit 9ac5ab2

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

packages/vite/src/rscBuild.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ export async function rscBuild(viteConfigPath: string) {
2525
root: rwPaths.base,
2626
plugins: [
2727
react(),
28-
{
29-
name: 'rsc-test-plugin',
30-
transform(_code, id) {
31-
console.log('rsc-test-plugin id', id)
32-
},
33-
},
28+
// {
29+
// name: 'rsc-test-plugin',
30+
// transform(_code, id) {
31+
// console.log('rsc-test-plugin id', id)
32+
// },
33+
// },
3434
rscAnalyzePlugin(
3535
(id) => clientEntryFileSet.add(id),
3636
(id) => serverEntryFileSet.add(id)
3737
),
3838
],
3939
ssr: {
40+
// We can ignore everything that starts with `node:` because it's not going to be RSCs
4041
noExternal: /^(?!node:)/,
4142
// TODO (RSC): Figure out what the `external` list should be. Right
4243
// now it's just copied from waku

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ export async function serverBuild(
3333
// ...configFileConfig,
3434
root: rwPaths.web.base,
3535
ssr: {
36-
noExternal: true,
37-
// TODO (RSC): The code below is pretty much what waku does, but I don't
38-
// understand it
36+
// Externalize everything except files that have 'use client' in them
37+
// (this includes packages in node_modules that you use that have
38+
// 'use client' in them)
39+
// Files included in `noExternal` are files we want Vite to analyze
40+
noExternal: Object.values(clientEntryFiles),
41+
// TODO (RSC) This is the original code from waku. I think we can simplify it as above
42+
// The code below will for most basic cases just be `[ '..' ]`, which we
43+
// believe to be overly broad
3944
// noExternal: Object.values(clientEntryFiles).map((fname) => {
4045
// return path
41-
// .relative(path.join(rwPaths.web.base, 'node_modules'), fname)
46+
// .relative(path.join(rwPaths.base, 'node_modules'), fname)
4247
// .split('/')[0]
4348
// }),
4449
},

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

-6
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ const vitePromise = createServer({
155155
resolve: {
156156
conditions: ['react-server'],
157157
},
158-
ssr: {
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'],
163-
},
164158
appType: 'custom',
165159
})
166160

0 commit comments

Comments
 (0)