Skip to content

Name the third-party package in sync IO prerender errors - #102471

Draft
aurorascharff wants to merge 5 commits into
codex/suggest-browser-for-sync-iofrom
aurora/sync-io-third-party-package
Draft

aurorascharff wants to merge 5 commits into
codex/suggest-browser-for-sync-iofrom
aurora/sync-io-third-party-package

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

When a dependency reads the clock, Math.random(), or a sync crypto API during prerendering, the error now names that package. It doesn't add any dependency stack frames.

Stacked on #99677. When a package is named, “Learn more” links to the external-library section on the matching error page. That section points to the applicable fixes; each card still links directly to its own recipe. The sections landed in #102245 (for example, current time in an external library).

Why

The dependency's frames are ignore-listed, so the error either blames the app component that rendered it or collapses to at ignore-listed frames. That happens with the default next build. The developer can't tell which library made the read or where in their app to apply the fix. Reports include carousel React wrappers that create their instance during render, and pg calling crypto.getRandomValues().

Before (Turbopack, default next build):

Error: Route "/server-time": Next.js encountered the unstable value `new Date()` while prerendering.

This value can change between renders, ...
    at ignore-listed frames

After:

Error: Route "/server-time": Next.js encountered the unstable value `new Date()` while prerendering.

This value can change between renders, ... The call comes from the `external-time` package.

Learn more: https://nextjs.org/docs/messages/blocking-prerender-current-time#when-the-read-comes-from-an-external-library
    at ignore-listed frames

The dev overlay title doesn't change. The package appears after the explanation in the same paragraph: "The call comes from the external-time package." The existing "Learn more" link points to the external-library subsection on the relevant error page, matching the terminal output.

Approach

This replaces #102189 and #102292. Ignore-listing and stack ordering are unchanged everywhere, so the top frame stays in code the user owns, which is where the fix goes. Only the package name is added, as one sentence after the explanation, so no frames push user code down the stack. It shows up the same way in the default build, --debug-prerender, the terminal, and the overlay.

  • patch-error-inspect gets findThirdPartyPackageInStack(). It source-maps the frames the same way error printing does, skips framework frames, and returns the package of the first ignore-listed frame inside node_modules. If it reaches a frame the user owns first, it returns null, so reads in app code are unchanged. It is shared via globalThis (like the code frame renderer) and only installed when source maps are enabled.
  • io() asks for the caller when it creates a sync IO error (prerender, client prerender, and dev validation stages). Attribution is best-effort and can't mask the actual error.
  • getThirdPartyPackageName() uses the innermost node_modules segment. That handles scoped packages and pnpm's virtual store. It excludes Next.js, React, scheduler, styled-jsx, @swc/helpers, @next/*, and anything installed inside next.
  • When a package is named, "Learn more" points to #when-the-read-comes-from-an-external-library on the relevant error page. Those sections are provided by Docs: clarify prerender errors for time, randomness, and crypto #102245.
  • The overlay reads the package from the message and appends it to the existing explanation. It uses the same wording and documentation link as the terminal, without adding a separate callout or button.

Limitation: with Webpack, server source maps exist only with --debug-prerender or experimental.serverSourceMaps. Without them, a bundled dependency can't be told apart from app code, so the message stays unchanged. Packages in serverExternalPackages are named either way.

Validation

On top of #99677, the attribution patch has the same added and removed lines as the standalone version. All 202 focused package, overlay, and guidance unit tests passed, and all 17 cards match the six error pages. The stack merges cleanly with canary, including all six external-library anchors. At the time of the restack, those sections were not yet live on nextjs.org. Full build and browser suites were not rerun for this restack.

Validation before this update:

New e2e suite test/e2e/app-dir/sync-io-third-party-package covers a bundled server dependency reading the clock, a serverExternalPackages dependency calling crypto.getRandomValues(), a dependency rendered from a Client Component, and a control where app code reads new Date() and no package is named.

  • pnpm test-start-turbo: 8/8, with and without --debug-prerender
  • pnpm test-start-webpack: 8/8, including the source-map limitation above
  • pnpm test-dev-turbo: 4/4 (redbox)
  • pnpm test-dev-webpack: 4/4 (redbox)
  • Unit: third-party-package.test.ts (path parsing) and errors.test.ts (overlay classification): 172 passed
  • test/production/next-server-nft: snapshot updated for the new server/lib/third-party-package.js, 6/6
  • pnpm --filter=next types, ESLint, and Prettier pass

Screenshots

Light Dark
Server Component Server Component, light theme Server Component, dark theme
Client Component Client Component, light theme Client Component, dark theme

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: b1a50ac
View workflow run

@github-actions github-actions Bot added created-by: Next.js team PRs by the Next.js team. tests type: next Documentation Related to Next.js' official documentation. labels Nov 26, 2026
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from d8311c5 to 5035653 Compare November 27, 2026 10:43
@aurorascharff
aurorascharff changed the base branch from canary to codex/suggest-browser-for-sync-io November 27, 2026 10:44
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from 5035653 to 5275c96 Compare November 27, 2026 10:53
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch 2 times, most recently from f408331 to c08a3bd Compare November 27, 2026 11:02
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from c08a3bd to ae431c9 Compare November 27, 2026 11:05
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from ae431c9 to d903838 Compare November 27, 2026 11:11
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from d903838 to d0cf1a1 Compare November 27, 2026 11:13
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from d0cf1a1 to 39ce52a Compare November 27, 2026 11:20
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from 39ce52a to 3b825b1 Compare November 27, 2026 13:33
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from 3b825b1 to df106ae Compare November 27, 2026 13:43
aurorascharff added a commit that referenced this pull request Nov 27, 2026
)

## 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](https://github.com/vercel/next.js/blob/canary/docs/01-app/02-guides/client-side-data-fetching/tanstack-query.mdx#build-a-prerenderable-hydration-state)
or [wrap the query component in Suspense on the
client](https://github.com/vercel/next.js/blob/canary/docs/01-app/02-guides/client-side-data-fetching/tanstack-query.mdx#use-suspense-for-client-data).
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

- Parsed all 105 JS/TS snippets across the eight changed pages. All 92
JSX/TSX snippets pass React's purity, set-state-in-effect, and refs
rules.
- Prettier and MDX ESLint pass. The CI link checker's read-only
validation passes for 317 internal links across the eight pages. All 17
overlay fix cards match their error pages in order, wording, snippets,
and links.
- [Runnable
reproductions](aurorascharff/reproductions#3)
and [hosted production build and browser
checks](https://github.com/aurorascharff/reproductions/actions/runs/45258382066)
on Next.js 16.4.6 previously verified server fixes, session prefetch
after request data, and hydration. Recomputing a timestamp in a
request-time Client Component produced React #418; serialized server
props and post-mount reads hydrated cleanly. The latest documentation
edits have not had a new browser run.

<!-- NEXT_JS_LLM -->
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch 2 times, most recently from 3e04979 to 74d2aca Compare November 27, 2026 13:54
@aurorascharff
aurorascharff removed this pull request from stack #102384 November 27, 2026 14:07
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from 74d2aca to 1b5cbc0 Compare November 27, 2026 14:08
@aurorascharff
aurorascharff changed the base branch from codex/suggest-browser-for-sync-io to canary November 27, 2026 14:08
@aurorascharff
aurorascharff force-pushed the aurora/sync-io-third-party-package branch from 1b5cbc0 to f363772 Compare November 27, 2026 14:20
@aurorascharff
aurorascharff changed the base branch from canary to codex/suggest-browser-for-sync-io November 27, 2026 14:20

This branch has not been deployed

No deployments
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. tests type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant