Skip to content

Docs: clarify prerender errors for time, randomness, and crypto - #102245

Merged
aurorascharff merged 35 commits into
canaryfrom
codex/docs-clock-reads-during-migration
Nov 27, 2026
Merged

aurorascharff merged 35 commits into
canaryfrom
codex/docs-clock-reads-during-migration

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Correct the sync IO guidance across the Cache Components migration guide, the six error pages, and the connection() reference. Build on the browser-only rendering guidance merged in #102401: lead with use(browser()) for browser-only library rendering, distinguish module imports and lazy loading, and link to the SPA guide for those details.

Server examples suspend before a fresh read with await io() under a parent Suspense boundary, retain connection() as an alternative, and show caching for reusable values. The three Client Component pages first show where to wrap the component in <Suspense>. For values that client code also needs, pass the server value as a prop so hydration reuses it. The migration guide makes the same server/client distinction.

When a package is named, #102471 links to the external-library section on the matching error page. Each section distinguishes the library calls or inputs that can be cached on the server from reads that must be fresh or happen during client rendering. The two clock errors also link directly to the existing TanStack Query guide: cache the hydration timestamp on the server or wrap the query component in Suspense on the client. The request ID label stays in the shell while only its value loads. Clarify that a driver can read time or randomness before its async query suspends, and that request APIs may resolve during runtime prerendering with Partial Prefetching. Separate data generation and timing instrumentation from component rendering so the examples pass React's purity rule.

Verification

@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent finished reviewing your changes and found no issues.
14fec73 • Mon, 23 Nov 2026 21:13:24 GMT • 1m 35s • Details

Checked (4)

     Check Location
All newly added internal documentation links and anchors resolve.
Ran a script resolving 60 added internal links and anchors against repository MDX files and headings across all nine changed pages.
building.mdx:98
The dependency-stack diagnostic uses the implemented opt-in environment variable.
Traced __NEXT_SHOW_IGNORE_LISTED === 'true' in patch-error-inspect.ts:484 and its ignored-frame output branch at line 565.
building.mdx:100
The request-time examples place io() before synchronous reads under a parent Suspense boundary.
Compared the three server recipes with io.ts:65-80, which hangs during build-time, client, and runtime prerendering and resolves for production requests.
blocking-prerender-current-time.mdx:81
All six error pages preserve their overlay fix cards.
Ran exact merge-base comparisons of every changed error page's FixCardGrid contents; all six matched.
blocking-prerender-crypto-client.mdx:31
Review steps

     Step Time
Preparing the workspace 20.6s
Analyzing the changes 1m 11s
Finalizing the review 2.9s

@github-actions github-actions Bot added the Documentation Related to Next.js' official documentation. label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: fb4e795
View workflow run

@aurorascharff aurorascharff changed the title Docs: clarify clock reads when migrating to Cache Components Docs: clarify prerender errors for time, randomness, and crypto Nov 23, 2026
@aurorascharff
aurorascharff marked this pull request as ready for review November 23, 2026 20:26

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vercel Agent Verified Review reviewed this commit. Not approving: the review didn’t come back Looks good. 1 open finding, listed in the status comment and inline. Report

#### Pass a server-generated value to the client

If the random value needs to be part of the server-rendered HTML (not deferred to after hydration), the component can call [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) during render as long as a [`<Suspense>`](https://react.dev/reference/react/Suspense) boundary wraps it from the parent. Next.js prerenders the fallback and fills in the real component at request time. See [`Math.random()` in a Client Component](/docs/messages/blocking-prerender-random-client) for the full recipe.
If the random value needs to appear in the server-rendered HTML, [generate it on the server](#generate-on-every-request) and [pass it as a prop](/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components) so the first browser render uses the same value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Unverified · Minor — Linked -client pages still recommend the Suspense recipe this PR drops

The random page replaces the 'Inline render with a parent <Suspense> boundary' pattern with 'pass a server-generated value as a prop'. The PR description gives the reason: recomputing the value in a Client Component caused React #418. The random page still links to blocking-prerender-random-client from Learn more and from its unchanged Gotchas line, and that page still recommends wrapping in Suspense (line 56). Its line 189 says to use Suspense when the value must be 'hydration-stable'. blocking-prerender-current-time-client line 68 gives the same advice. Readers now get conflicting fixes depending on which page they land on. This is a judgment call: those pages aren't in the diff, and the base already had the same advice there.

Not checked by a repro: Its trace points at lines the head has, but a trace isn’t run: follow it to judge.

Unverified: its repro didn’t settle it, so a person should judge it.

@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent Verified Review ? confirmed no issues. 1 finding needs your judgment.
fb4e795 • Ran Fri, 27 Nov 2026 13:46:20 GMT • 2m 0s • Read the full report ↗

Summary

Docs-only change. It rewrites the six sync-IO prerender error pages, the Cache Components migration step and the connection() reference. Server fixes now lead with await io() (and keep connection() as an alternative). The client pages drop the use(io()) section and lead with a parent <Suspense>, effects or event handlers, or passing a server value as a prop. Each page gains an external-library section. I found nothing new on this head. The earlier finding c1 still stands: the FixCards at the top of the page and the overlay cards still show await connection() and "use client" // runs in the browser. Prettier passes on the changed files. I checked every new anchor by reading. I did not run a browser or hydration check.

Questions for the author (2)

  • The lead client fix ('Place Suspense above the Client Component') clears the prerender error, but the component still server-renders at request time. If it renders Date.now() or a random value, hydration will mismatch (your description mentions React Routing questions - params patterns like: "/profile/:id/edit" and server db -how to pass data to react components? #418). The base's RelativeTime example had suppressHydrationWarning, and this PR removes that example. Is the one-line 'if both the server and the browser display…pass it as a prop' caveat enough, or should the Suspense section say outright tha…
  • In blocking-prerender-current-time-client.mdx, the new Suspense example wraps the whole page body (<Suspense><TimeDisplay /></Suspense> returned from Page). The same page's 'Verifying the fix' section warns against exactly that. Should the example keep some shell around the boundary?

Issues (1)

Severity Issue Location
Low Unverified since 31173b9: Fix cards still say 'use client' runs the read in the browser blocking-prerender-random.mdx:60
Checked (6)

     Check Location
Passed Every newly added cross-page anchor resolves to an existing heading in the head.
Grepped headings in building, server-and-client-components, io, single-page-applications, tanstack-query and streaming docs; every new anchor target exists.
blocking-prerender-current-time.mdx:312
Passed Removing the old 'Wrap from a Server Component parent' heading doesn't break inbound links, because a <span id> keeps the old anchor.
Read the span in all three client pages. Grepped the repo for removed anchors (suspend-with-useio, other-options, inline-render-with-a-parent…) and found no references left.
blocking-prerender-current-time-client.mdx:70
Passed The io() used by the new lead server snippets is exported from next/cache for server code.
Read packages/next/cache.js and cache.d.ts. Both export io from next/dist/server/request/io.
blocking-prerender-random.mdx:91
Passed The cached API-token snippet now imports randomBytes from node:crypto instead of calling the nonexistent global crypto.randomBytes.
Read the head snippet. The global Web Crypto object has no randomBytes, so the base snippet would have thrown.
blocking-prerender-crypto.mdx:186
Passed The rewritten 'stable ID with useRef' prose matches its snippets: the ID is generated lazily in the onClick handler, not during render.
Read the snippets in crypto-client.mdx and random-client.mdx. getOrCreateId(idRef) is called only inside onClick.
blocking-prerender-crypto-client.mdx:146
Passed The changed pages pass Prettier.
Ran prettier --check on all eight changed files via verify-exec on the head. All passed.
migrating-to-cache-components.mdx:101
Review steps

     Step Time
Sandbox set up 13.9s
Agent review: 2 commands run 1m 44s
Repros run on the head and the base (0), findings graded (1) 1.7s

Confirmed: its repro failed on this commit and not the same way on the base. Unverified: a person should judge it.

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vercel Agent Verified Review reviewed this commit. Not approving: the review didn’t come back Looks good. 1 open finding, listed in the status comment and inline. Report

Comment thread errors/blocking-prerender-random.mdx Outdated
### Gotchas

- A Client Component that produces a random value inline during render still trips this error during SSR. See the dedicated [`Math.random()` in a Client Component](/docs/messages/blocking-prerender-random-client) page for the [`<Suspense>`](https://react.dev/reference/react/Suspense) and effect-based recipes.
- A parent `<Suspense>` boundary can show a fallback during prerendering. If the Client Component renders at request time, the boundary does not preserve its random value for hydration. [Pass the server value as a prop](#pass-a-server-generated-value-to-the-client) instead of calling `Math.random()` again in the browser.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Unverified · Major — New Math.random gotcha contradicts the unchanged *-client pages' Suspense fix

The PR removes the 'Inline render with a parent <Suspense> boundary' pattern from blocking-prerender-random.mdx. In its place, a gotcha says a parent Suspense boundary 'does not preserve its random value for hydration', and the description reports React #418 for that setup. But blocking-prerender-random-client.mdx (and current-time-client) still recommends exactly that fix as its primary one: 'Wrap in or move into Suspense… Next.js fills in the real component when the browser hydrates'. Its gotcha also says 'If the value needs to be hydration-stable… use Wrap in or move into Suspense instead'. The current-time and crypto pages still point readers to those 'Suspense and effect-based recipes'. A reader who follows those links implements the pattern this PR calls broken. REVIEW.md's no-stale-docs rule (review/rules/no-stale-docs.md) treats this as medium: 'Prose, headings, snippets, expected output, or related pages giving incompatible instructions'. The docs rubric (review/areas/docs.…

Not checked by a repro: Its trace points at lines the head has, but a trace isn’t run: follow it to judge.

Unverified: its repro didn’t settle it, so a person should judge it.

@vercel
vercel Bot requested a review from icyJoseph November 23, 2026 20:36
aurorascharff added a commit that referenced this pull request Nov 23, 2026
When a Server Component calls a synchronous Node crypto API such as
`randomBytes(16)` during prerendering, the terminal names the right
function but links to the `Math.random()` error page. The dev overlay
already links the same call to the crypto page.

Classify the seven instrumented `node:crypto` calls as crypto so the
terminal prints the same link:

```diff
-Learn more: https://nextjs.org/docs/messages/blocking-prerender-random
+Learn more: https://nextjs.org/docs/messages/blocking-prerender-crypto
```

## Verification

- Exercised all seven Node API wrappers against the diagnostic factories
before and after the change. Checked the server, runtime-prerender, and
client error URLs, with `Math.random()` and callback-based `randomBytes`
and `randomInt` as controls.
- Updated the 32 affected production build snapshots across eight routes
in the existing end-to-end suite. The four `getRandomValues` snapshots
already pointed to the crypto page.

Found while reviewing #102245. This fix can merge independently.

<!-- NEXT_JS_LLM -->

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vercel Agent Verified Review reviewed this commit. Not approving: the review didn’t come back Looks good. 1 open finding, listed in the status comment and inline. Report

## Wrap in or move into Suspense

Choose this fix when the random value is part of the rendered output and a brief fallback during SSR is acceptable. Wrap the consuming Client Component in [`<Suspense>`](https://react.dev/reference/react/Suspense) from its parent. The fallback ships in the prerendered HTML, and Next.js fills in the real component when the browser hydrates.
Choose this fix when the random value is part of the rendered output and a brief fallback during SSR is acceptable. Wrap the consuming Client Component in [`<Suspense>`](https://react.dev/reference/react/Suspense) from its parent. Next.js can prerender the fallback. If the Client Component renders on the server at request time, the browser can compute a different random value during hydration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Unverified · Minor — Client error pages still recommend the Suspense recipe that now admits mismatch

The change corrects the Server Component page's gotcha to say a parent <Suspense> boundary does not preserve a random value for hydration, so use a server prop instead (random.mdx:226). The intro of the matching client section now also says the browser can compute a different value. But random-client.mdx and crypto-client.mdx still present 'Wrap in or move into Suspense' as a fix for a value that is 'part of the rendered output', and their examples call Math.random()/crypto.randomUUID() inline with no suppressHydrationWarning (the time page has one). The PR description says this pattern produced React #418. Readers who follow the client page's first fix card get the hydration error that the sibling page warns about.

Not checked by a repro: Its trace points at lines the head has, but a trace isn’t run: follow it to judge.

Unverified: its repro didn’t settle it, so a person should judge it.

vercel[bot]
vercel Bot previously approved these changes Nov 23, 2026

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vercel Agent Verified Review approves this commit: no issues found, and the change meets this repository’s review rules. Report

@vercel
vercel Bot dismissed their stale review November 25, 2026 20:58

Vercel Agent Verified Review reviewed a newer commit and didn’t approve it: dismissing its approval of an earlier commit.

@aurorascharff
aurorascharff marked this pull request as draft November 25, 2026 22:07
@aurorascharff
aurorascharff marked this pull request as ready for review November 27, 2026 13:33
@aurorascharff
aurorascharff enabled stacked auto-merge (squash) November 27, 2026 13:44
@aurorascharff
aurorascharff merged commit 0125444 into canary Nov 27, 2026
59 checks passed
@aurorascharff
aurorascharff deleted the codex/docs-clock-reads-during-migration branch November 27, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Next.js team PRs by the Next.js team. Documentation Related to Next.js' official documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants