From 8917ad6ab5eaea40f6a79b478e28df4b9c43182f Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 7 Jul 2023 12:02:47 +0200 Subject: [PATCH] Update entry.client and disable vite legacy mode (#8851) --- .../commands/experimental/setupRscHandler.js | 20 ++++++++++++++++++- .../templates/rsc/entry.client.tsx.template | 10 ++++++++++ packages/vite/src/index.ts | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/commands/experimental/templates/rsc/entry.client.tsx.template diff --git a/packages/cli/src/commands/experimental/setupRscHandler.js b/packages/cli/src/commands/experimental/setupRscHandler.js index 4612e883f626..64b46bbc2671 100644 --- a/packages/cli/src/commands/experimental/setupRscHandler.js +++ b/packages/cli/src/commands/experimental/setupRscHandler.js @@ -94,7 +94,7 @@ export const handler = async ({ force, verbose }) => { }, }, { - title: 'Updating App.tsx...', + title: 'Overwriting App.tsx...', task: async () => { const appTemplate = fs.readFileSync( path.resolve(__dirname, 'templates', 'rsc', 'App.tsx.template'), @@ -135,6 +135,24 @@ export const handler = async ({ force, verbose }) => { }) }, }, + { + title: 'Overwrite entry.client.tsx...', + task: async () => { + const entryClientTemplate = fs.readFileSync( + path.resolve( + __dirname, + 'templates', + 'rsc', + 'entry.client.tsx.template' + ), + 'utf-8' + ) + + writeFile(rwPaths.web.entryClient, entryClientTemplate, { + overwriteExisting: true, + }) + }, + }, { task: () => { printTaskEpilogue(command, description, EXPERIMENTAL_TOPIC_ID) diff --git a/packages/cli/src/commands/experimental/templates/rsc/entry.client.tsx.template b/packages/cli/src/commands/experimental/templates/rsc/entry.client.tsx.template new file mode 100644 index 000000000000..b75d5d728476 --- /dev/null +++ b/packages/cli/src/commands/experimental/templates/rsc/entry.client.tsx.template @@ -0,0 +1,10 @@ +import { createRoot } from 'react-dom/client' + +import { serve } from '@redwoodjs/vite/client' + +const redwoodAppElement = document.getElementById('redwood-app') + +const App = serve('App') + +const root = createRoot(redwoodAppElement) +root.render() diff --git a/packages/vite/src/index.ts b/packages/vite/src/index.ts index 22ae0a5a299c..1684cb7299e9 100644 --- a/packages/vite/src/index.ts +++ b/packages/vite/src/index.ts @@ -170,9 +170,10 @@ export default function redwoodPluginVite(): PluginOption[] { manifest: !env.ssrBuild ? 'build-manifest.json' : undefined, sourcemap: !env.ssrBuild && rwConfig.web.sourceMap, // Note that this can be boolean or 'inline' }, - // To produce a cjs bundle for SSR legacy: { - buildSsrCjsExternalHeuristics: env.ssrBuild, + buildSsrCjsExternalHeuristics: rwConfig.experimental?.rsc?.enabled + ? false + : env.ssrBuild, }, optimizeDeps: { esbuildOptions: {