Skip to content

Commit 3bc5afc

Browse files
committed
Ensure bootprops are also passed to the layout at render time
1 parent 9f63761 commit 3bc5afc

File tree

4 files changed

+21
-40
lines changed

4 files changed

+21
-40
lines changed

packages/fastify-renderer/src/node/renderers/react/ReactRenderer.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,19 @@ export class ReactRenderer implements Renderer {
8282
const hooks = this.plugin.hooks.map(unthunk)
8383

8484
try {
85-
const url = this.entrypointRequirePathForServer(render)
85+
const requirePath = this.entrypointRequirePathForServer(render)
8686

8787
// we load all the context needed for this render from one `loadModule` call, which is really important for keeping the same copy of React around in all of the different bits that touch it.
88-
const { React, ReactDOMServer, Router, RenderBusContext, Layout, Entrypoint } = (await this.loadModule(url))
89-
.default
88+
const { React, ReactDOMServer, Router, RenderBusContext, Layout, Entrypoint } = (
89+
await this.loadModule(requirePath)
90+
).default
91+
92+
const destination = this.stripBasePath(render.request.url, render.base)
9093

9194
let app = (
9295
<RenderBusContext.Provider value={bus}>
93-
<Router base={render.base} hook={staticLocationHook(this.stripBasePath(render.request.url, render.base))}>
94-
<Layout>
96+
<Router base={render.base} hook={staticLocationHook(destination)}>
97+
<Layout isNavigating={false} navigationDestination={destination} bootProps={render.props}>
9598
<Entrypoint {...render.props} />
9699
</Layout>
97100
</Router>

packages/test-apps/simple-react/BootPropsLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Layout = (props: { children: React.ReactNode; bootProps: Record<string, an
44
return (
55
<Suspense fallback={<div>Loading...</div>}>
66
<pre id="bootprops">
7-
<code>{JSON.stringify(props.bootProps)}</code>
7+
<code>{props.bootProps.someValue}</code>
88
</pre>
99
{props.children}
1010
</Suspense>

packages/test-apps/simple-react/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const server = async () => {
7575
instance.setRenderConfig({ base: '/bootprops', layout: require.resolve('./BootPropsLayout') })
7676

7777
instance.get('/bootprops/test', { render: require.resolve('./About') }, async (request) => {
78-
return { hostname: os.hostname(), requestIP: request.ip, bootProp: 'this is a boot prop' }
78+
return { hostname: os.hostname(), requestIP: request.ip, someValue: 'this is a boot prop' }
7979
})
8080
})
8181

yarn.lock

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,17 +1369,17 @@
13691369
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
13701370
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
13711371

1372-
"@types/react-dom@^17.0.11":
1373-
version "17.0.17"
1374-
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.17.tgz#2e3743277a793a96a99f1bf87614598289da68a1"
1375-
integrity sha512-VjnqEmqGnasQKV0CWLevqMTXBYG9GbwuE6x3VetERLh0cq2LTptFE73MrQi2S7GkKXCf2GgwItB/melLnxfnsg==
1372+
"@types/react-dom@17.0.4", "@types/react-dom@^17.0.11":
1373+
version "17.0.4"
1374+
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.4.tgz#d65159a847aca2a0fc87a7544a2f8fece8754d04"
1375+
integrity sha512-Wb6rlnPJfqbhpkvYN39y1NM/pOGGPzzIRquu0RdUMvTwgXNvASFO7pdtrtvyxGTQNb9wzBaQxXAWDdEqegZw2A==
13761376
dependencies:
1377-
"@types/react" "^17"
1377+
"@types/react" "*"
13781378

1379-
"@types/react@^17", "@types/react@^17.0.43":
1380-
version "17.0.47"
1381-
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.47.tgz#4ee71aaf4c5a9e290e03aa4d0d313c5d666b3b78"
1382-
integrity sha512-mk0BL8zBinf2ozNr3qPnlu1oyVTYq+4V7WA76RgxUAtf0Em/Wbid38KN6n4abEkvO4xMTBWmnP1FtQzgkEiJoA==
1379+
"@types/react@*", "@types/[email protected]", "@types/react@^17.0.43":
1380+
version "17.0.4"
1381+
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.4.tgz#a67c6f7a460d2660e950d9ccc1c2f18525c28220"
1382+
integrity sha512-onz2BqScSFMoTRdJUZUDD/7xrusM8hBA2Fktk2qgaTYPCgPvWnDEgkrOs8hhPUf2jfcIXkJ5yK6VfYormJS3Jw==
13831383
dependencies:
13841384
"@types/prop-types" "*"
13851385
"@types/scheduler" "*"
@@ -5895,15 +5895,7 @@ [email protected]:
58955895
iconv-lite "0.4.24"
58965896
unpipe "1.0.0"
58975897

5898-
react-dom@*:
5899-
version "18.2.0"
5900-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
5901-
integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==
5902-
dependencies:
5903-
loose-envify "^1.1.0"
5904-
scheduler "^0.23.0"
5905-
5906-
5898+
react-dom@*, [email protected]:
59075899
version "0.0.0-experimental-4ead6b530"
59085900
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-0.0.0-experimental-4ead6b530.tgz#6ca831f5aa7ab86f7299b9a2f7b81dffabfa4eb4"
59095901
integrity sha512-a03ptS8lhhEENNgne6zQMXQWX/Z6WMEBGJQY0laOC0NgJywidePYpgkiE72fUAaj/r7t9a6XsdVyqx4UsEZijg==
@@ -5927,14 +5919,7 @@ react-refresh@^0.10.0:
59275919
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.10.0.tgz#2f536c9660c0b9b1d500684d9e52a65e7404f7e3"
59285920
integrity sha512-PgidR3wST3dDYKr6b4pJoqQFpPGNKDSCDx4cZoshjXipw3LzO7mG1My2pwEzz2JVkF+inx3xRpDeQLFQGH/hsQ==
59295921

5930-
react@*:
5931-
version "18.2.0"
5932-
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
5933-
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
5934-
dependencies:
5935-
loose-envify "^1.1.0"
5936-
5937-
5922+
59385923
version "0.0.0-experimental-4ead6b530"
59395924
resolved "https://registry.yarnpkg.com/react/-/react-0.0.0-experimental-4ead6b530.tgz#88cdae012012a758dd039a63104758c6351115df"
59405925
integrity sha512-tpbYm6FEuC1L6tCVXIKYAhgGAkS8DShzKpmXosowZvLqeByeLQQe77Ef6bi5HdEkFm2v0lZffLWckSM8R4TToA==
@@ -6193,13 +6178,6 @@ [email protected]:
61936178
loose-envify "^1.1.0"
61946179
object-assign "^4.1.1"
61956180

6196-
scheduler@^0.23.0:
6197-
version "0.23.0"
6198-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
6199-
integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==
6200-
dependencies:
6201-
loose-envify "^1.1.0"
6202-
62036181
secure-json-parse@^2.0.0:
62046182
version "2.4.0"
62056183
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.4.0.tgz#5aaeaaef85c7a417f76271a4f5b0cc3315ddca85"

0 commit comments

Comments
 (0)