From 68abdbb0cb7c39ab1b08d2d1ce5fe0c544e5308b Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Tue, 7 Nov 2023 15:21:14 +0700 Subject: [PATCH 1/3] Disable copying index when ssr enabled --- packages/cli/src/commands/buildHandler.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/buildHandler.js b/packages/cli/src/commands/buildHandler.js index f6bb7a08029f..dcb17dba2e86 100644 --- a/packages/cli/src/commands/buildHandler.js +++ b/packages/cli/src/commands/buildHandler.js @@ -138,14 +138,17 @@ export const handler = async ({ ) } - console.log('Creating 200.html...') + // Streaming SSR does not use the index.html file. + if (!getConfig().experimental?.streamingSsr?.enabled) { + console.log('Creating 200.html...') - const indexHtmlPath = path.join(getPaths().web.dist, 'index.html') + const indexHtmlPath = path.join(getPaths().web.dist, 'index.html') - fs.copyFileSync( - indexHtmlPath, - path.join(getPaths().web.dist, '200.html') - ) + fs.copyFileSync( + indexHtmlPath, + path.join(getPaths().web.dist, '200.html') + ) + } }, }, ].filter(Boolean) From 60379a5500e287365953efb44062d5340537cffd Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Tue, 7 Nov 2023 15:21:51 +0700 Subject: [PATCH 2/3] Remove rollup options from buildFeServer --- packages/vite/src/buildFeServer.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/buildFeServer.ts b/packages/vite/src/buildFeServer.ts index 3755346e1414..8aa0a67f48cb 100644 --- a/packages/vite/src/buildFeServer.ts +++ b/packages/vite/src/buildFeServer.ts @@ -71,13 +71,8 @@ export const buildFeServer = async ({ verbose, webDir }: BuildOptions = {}) => { configFile: viteConfigPath, build: { outDir: rwPaths.web.distServer, - ssr: true, // use boolean, and supply the inputs in rollup options (see Documentation) - rollupOptions: { - input: { - 'entry.server': rwPaths.web.entryServer, - Document: rwPaths.web.document, // We need the document for React's fallback - }, - }, + ssr: true, // use boolean here, instead of string. + // rollup inputs are defined in the vite plugin }, envFile: false, logLevel: verbose ? 'info' : 'warn', From 461bccb404531fb577bdb72dbb3b58e60561e6ca Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Tue, 7 Nov 2023 15:34:23 +0700 Subject: [PATCH 3/3] Change rollup input for ssr-streaming --- packages/vite/src/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/vite/src/index.ts b/packages/vite/src/index.ts index f394a266674e..9e186189d697 100644 --- a/packages/vite/src/index.ts +++ b/packages/vite/src/index.ts @@ -2,6 +2,7 @@ import { existsSync } from 'fs' import path from 'path' import react from '@vitejs/plugin-react' +import type { InputOption } from 'rollup' import type { ConfigEnv, UserConfig, PluginOption } from 'vite' import { normalizePath } from 'vite' @@ -240,6 +241,9 @@ export default function redwoodPluginVite(): PluginOption[] { emptyOutDir: true, manifest: !env.ssrBuild ? 'build-manifest.json' : undefined, sourcemap: !env.ssrBuild && rwConfig.web.sourceMap, // Note that this can be boolean or 'inline' + rollupOptions: { + input: getRollupInput(!!env.ssrBuild), + }, }, legacy: { buildSsrCjsExternalHeuristics: rwConfig.experimental?.rsc?.enabled @@ -281,3 +285,32 @@ export default function redwoodPluginVite(): PluginOption[] { }), ] } + +/** + * + * This function configures how vite (actually Rollup) will bundle. + * + * By default, the entry point is the index.html file - even if you don't specify it in RollupOptions + * + * With streaming SSR, out entrypoint is different - either entry.client.tsx or entry.server.tsx + * and the html file is not used at all, because it is defined in Document.tsx + * + * @param ssr {boolean} Whether to return the SSR inputs or not + * @returns Rollup input Options + */ +function getRollupInput(ssr: boolean): InputOption | undefined { + const rwConfig = getConfig() + const rwPaths = getPaths() + + // @NOTE once streaming ssr is out of experimental, this will become the default + if (rwConfig.experimental.streamingSsr.enabled) { + return ssr + ? { + 'entry.server': rwPaths.web.entryServer as string, + Document: rwPaths.web.document, // We need the document for React's fallback + } + : (rwPaths.web.entryClient as string) + } + + return rwPaths.web.html +}