Skip to content

Commit 93e0257

Browse files
authored
chore: provide slice rendering context to <HTML> (#36799)
1 parent 61f197d commit 93e0257

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/gatsby/cache-dir/static-entry.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ export default async function staticPage({
283283
}
284284
).pop()
285285

286+
const slicesContext = {
287+
// if we're in build now, we know we're on the server
288+
// otherwise we're in an engine
289+
renderEnvironment: renderContext.isDuringBuild ? `server` : `engines`,
290+
}
286291
if (process.env.GATSBY_SLICES) {
287-
const slicesContext = {
288-
// if we're in build now, we know we're on the server
289-
// otherwise we're in an engine
290-
renderEnvironment: renderContext.isDuringBuild ? `server` : `engines`,
291-
}
292292
// if we're running in an engine, we need to manually wrap body with
293293
// the results context to pass the map of slice name to component/data/context
294294
if (slicesContext.renderEnvironment === `engines`) {
@@ -509,7 +509,7 @@ export default async function staticPage({
509509
pathPrefix: __PATH_PREFIX__,
510510
})
511511

512-
const html = `<!DOCTYPE html>${renderToStaticMarkup(
512+
let htmlElement = (
513513
<Html
514514
{...bodyProps}
515515
headComponents={headComponents}
@@ -520,7 +520,17 @@ export default async function staticPage({
520520
body={bodyHtml}
521521
path={pagePath}
522522
/>
523-
)}`
523+
)
524+
525+
if (process.env.GATSBY_SLICES) {
526+
htmlElement = (
527+
<SlicesContext.Provider value={slicesContext}>
528+
{htmlElement}
529+
</SlicesContext.Provider>
530+
)
531+
}
532+
533+
const html = `<!DOCTYPE html>${renderToStaticMarkup(htmlElement)}`
524534

525535
return {
526536
html,

0 commit comments

Comments
 (0)