Unverified Commit 0b5196f4 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Generate deterministic requestId for SSG (#79959)

Use a deterministic requestId so that this code has a deterministic key and thus a deterministic RSC payload to generate deterministic SSG output.
```javascript
            {/* Adding requestId as react key to make metadata remount for each render */}
            <ViewportTree key={getFlightViewportKey(requestId)} />
```

This was previously changing on every run:

<img width="1398" alt="Bildschirmfoto 2025-05-30 um 10 45 08" src="https://github.com/user-attachments/assets/36cb9864-9b27-4107-93d6-689c9d147e86" />
parent a0993d90
......@@ -1331,13 +1331,19 @@ async function renderToHTMLOrFlightImpl(
nonce,
} = parsedRequestHeaders
const { isStaticGeneration, fallbackRouteParams } = workStore
/**
* The metadata items array created in next-app-loader with all relevant information
* that we need to resolve the final metadata.
*/
let requestId: string
if (process.env.NEXT_RUNTIME === 'edge') {
if (isStaticGeneration) {
requestId = Buffer.from(
await crypto.subtle.digest('SHA-1', Buffer.from(req.url))
).toString('hex')
} else if (process.env.NEXT_RUNTIME === 'edge') {
requestId = crypto.randomUUID()
} else {
requestId = require('next/dist/compiled/nanoid').nanoid()
......@@ -1348,8 +1354,6 @@ async function renderToHTMLOrFlightImpl(
*/
const params = renderOpts.params ?? {}
const { isStaticGeneration, fallbackRouteParams } = workStore
const getDynamicParamFromSegment = makeGetDynamicParamFromSegment(
params,
pagePath,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment