Skip to content

Commit

Permalink
chore(ssr): Move LocationProvider inside framework for SSR (#9383)
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Nov 9, 2023
1 parent 1e42b43 commit c4dedc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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<Props> = ({ url, css, meta }) => {
export const ServerEntry: React.FC<Props> = ({ css, meta }) => {
return (
<LocationProvider location={{ pathname: url }}>
<Document css={css} meta={meta}>
<App />
</Document>
</LocationProvider>
<Document css={css} meta={meta}>
<App />
</Document>
)
}
19 changes: 14 additions & 5 deletions packages/vite/src/streaming/streamHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
})
)
)
}

Expand Down

0 comments on commit c4dedc6

Please sign in to comment.