From c1ebe32732b62ab8f8719b8e4485bba1193f6f69 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 25 Jul 2023 00:28:37 +0200 Subject: [PATCH 1/2] RSC: Fix noExternal rule for server build --- packages/vite/src/rscBuild.ts | 13 +++++++------ packages/vite/src/waku-lib/build-server.ts | 13 +++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/rscBuild.ts b/packages/vite/src/rscBuild.ts index ce49570ca43e..4fdbc764da55 100644 --- a/packages/vite/src/rscBuild.ts +++ b/packages/vite/src/rscBuild.ts @@ -25,18 +25,19 @@ export async function rscBuild(viteConfigPath: string) { root: rwPaths.base, plugins: [ react(), - { - name: 'rsc-test-plugin', - transform(_code, id) { - console.log('rsc-test-plugin id', id) - }, - }, + // { + // name: 'rsc-test-plugin', + // transform(_code, id) { + // console.log('rsc-test-plugin id', id) + // }, + // }, rscAnalyzePlugin( (id) => clientEntryFileSet.add(id), (id) => serverEntryFileSet.add(id) ), ], ssr: { + // We can ignore everything that starts with `node:` because it's not going to be RSCs noExternal: /^(?!node:)/, // TODO (RSC): Figure out what the `external` list should be. Right // now it's just copied from waku diff --git a/packages/vite/src/waku-lib/build-server.ts b/packages/vite/src/waku-lib/build-server.ts index 80d555356b4e..83e0f25a31e4 100644 --- a/packages/vite/src/waku-lib/build-server.ts +++ b/packages/vite/src/waku-lib/build-server.ts @@ -33,12 +33,17 @@ export async function serverBuild( // ...configFileConfig, root: rwPaths.web.base, ssr: { - noExternal: true, - // TODO (RSC): The code below is pretty much what waku does, but I don't - // understand it + // Externalize everything except files that have 'use client' in them + // (this includes packages in node_modules that you use that have + // 'use client' in them) + // Files included in `noExternal` are files we want Vite to analyze + noExternal: Object.values(clientEntryFiles), + // TODO (RSC) This is the original code from waku. I think we can simplify it as above + // The code below will for most basic cases just be `[ '..' ]`, which we + // believe to be overly broad // noExternal: Object.values(clientEntryFiles).map((fname) => { // return path - // .relative(path.join(rwPaths.web.base, 'node_modules'), fname) + // .relative(path.join(rwPaths.base, 'node_modules'), fname) // .split('/')[0] // }), }, From 12732b6cb66d87869f7cdf3d9b66fb8f69dd5c02 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 25 Jul 2023 01:27:47 +0200 Subject: [PATCH 2/2] Externalize everything for the server --- packages/vite/src/waku-lib/rsc-handler-worker.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/vite/src/waku-lib/rsc-handler-worker.ts b/packages/vite/src/waku-lib/rsc-handler-worker.ts index c7c4083727ea..31efb10c4991 100644 --- a/packages/vite/src/waku-lib/rsc-handler-worker.ts +++ b/packages/vite/src/waku-lib/rsc-handler-worker.ts @@ -155,12 +155,6 @@ const vitePromise = createServer({ resolve: { conditions: ['react-server'], }, - ssr: { - 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', })