From c4dedc66ced7259516715033c20372072c4cfd2d Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Thu, 9 Nov 2023 16:37:01 +0700 Subject: [PATCH] chore(ssr): Move LocationProvider inside framework for SSR (#9383) --- .../streamingSsr/entry.server.tsx.template | 13 ++++--------- packages/vite/src/streaming/streamHelpers.ts | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/commands/experimental/templates/streamingSsr/entry.server.tsx.template b/packages/cli/src/commands/experimental/templates/streamingSsr/entry.server.tsx.template index fda9b9b6a01c..a52b268b771d 100644 --- a/packages/cli/src/commands/experimental/templates/streamingSsr/entry.server.tsx.template +++ b/packages/cli/src/commands/experimental/templates/streamingSsr/entry.server.tsx.template @@ -1,20 +1,15 @@ -import { LocationProvider } from '@redwoodjs/router' - import App from './App' import { Document } from './Document' interface Props { - url: string css: string[] meta?: any[] } -export const ServerEntry: React.FC = ({ url, css, meta }) => { +export const ServerEntry: React.FC = ({ css, meta }) => { return ( - - - - - + + + ) } diff --git a/packages/vite/src/streaming/streamHelpers.ts b/packages/vite/src/streaming/streamHelpers.ts index eedd31a34d1f..7085a1189953 100644 --- a/packages/vite/src/streaming/streamHelpers.ts +++ b/packages/vite/src/streaming/streamHelpers.ts @@ -7,6 +7,7 @@ import type { ReactDOMServerReadableStream, } from 'react-dom/server' +import { LocationProvider } from '@redwoodjs/router' import type { TagDescriptor } from '@redwoodjs/web' // @TODO (ESM), use exports field. Cannot import from web because of index exports import { @@ -89,11 +90,19 @@ export async function reactRenderToStreamResponse( { value: injectToPage, }, - ServerEntry({ - url: path, - css: cssLinks, - meta: metaTags, - }) + React.createElement( + LocationProvider, + { + location: { + pathname: path, + }, + }, + ServerEntry({ + url: path, + css: cssLinks, + meta: metaTags, + }) + ) ) }