Skip to content

Show the component import in sync IO prerender code frames - #102292

Closed
aurorascharff wants to merge 3 commits into
canaryfrom
codex/prerender-codeframe-import
Closed

aurorascharff wants to merge 3 commits into
canaryfrom
codex/prerender-codeframe-import

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closed by #102471.

When a third-party component reads the clock, calls Math.random(), or generates a value with a synchronous crypto API during prerendering, the code frame can point to a JSX tag without naming its package. In the example below, the external-time dependency exports BlockingWidget and reads the clock. The app imports and renders that component. Show the import above the JSX, with the caret on the line the app author can edit.

This is an alternative to #102189, using its third-party date reproduction. Stack ordering and ignore-list behavior stay the same.

Before and after

Output from the shared code-frame renderer for the same mapped position in the fixture, with the import hint disabled and enabled:

Before

  4 |   return (
  5 |     <main>
> 6 |       <BlockingWidget />
    |       ^
  7 |     </main>
  8 |   )
  9 | }

After

  1 | import { BlockingWidget } from 'external-time'
  2 |
  3 | export default function Page() {
  4 |   return (
  5 |     <main>
> 6 |       <BlockingWidget />
    |       ^
  7 |     </main>
  8 |   )
  9 | }

The dev overlay and terminal opt into the hint for sync IO prerender diagnostics (time, random, and crypto). It needs a mapped application frame pointing at an opening JSX component tag. It resolves the local binding, including aliased imports, and shows the declaration in source order in the same numbered excerpt. Only the JSX use has a caret. For a distant import, an ellipsis marks the omitted lines. If the tag resolves to a local binding or relative import, the source cannot be parsed, or the file exceeds the size limit, the original code frame stands on its own. The import identifies the component's source; it does not claim the package owns the innermost clock read.

Verification

  • Exercised the compiled formatter with the fixture above; the control and expanded source windows are shown verbatim.
  • Focused tests cover shadowed bindings, aliased imports, and distant multiline imports above or below the JSX. The existing overlay classification suite also passed. The Next.js package type check, ESLint, and Prettier passed.
  • The end-to-end fixture covers new Date(), Date.now(), Math.random(), Web Crypto's crypto.getRandomValues(), and Node's randomUUID() from node:crypto. For each route it checks the failing expression and the corresponding app import in the dev overlay and debug build output. All five routes share one dev server and one debug build per test configuration.
  • A local smoke check exercised the five fixture exports through the instrumented APIs and confirmed the import was included for the server, runtime, and client error factories. An unrelated render error kept its normal frame. Browser and build integration coverage runs on hosted CI.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Failing test suites

Commit: 495c4f1 | About building and testing Next.js

pnpm test-dev test/development/app-dir/dev-indicator/hide-button.test.ts (job)

  • dev indicator - Hide DevTools Button > should visibly record a shortcut and let it toggle visibility immediately after saving (DD)
Expand output

● dev indicator - Hide DevTools Button › should visibly record a shortcut and let it toggle visibility immediately after saving

page.waitForSelector: Timeout 5000ms exceeded.
Call log:
  - waiting for locator('.shortcut-recorder-button') to be visible

  586 |
  587 |     return this.startChain(async () => {
> 588 |       const el = await page.waitForSelector(selector, {
      |                             ^
  589 |         timeout,
  590 |         state,
  591 |       })

  at waitForSelector (lib/browsers/playwright.ts:588:29)
  at Playwright._chain (lib/browsers/playwright.ts:718:23)
  at Playwright._chain [as startChain] (lib/browsers/playwright.ts:699:17)
  at Playwright.startChain [as waitForElementByCss] (lib/browsers/playwright.ts:587:17)
  at Playwright.waitForElementByCss [as elementByCss] (lib/browsers/playwright.ts:472:17)
  at elementByCss (development/app-dir/dev-indicator/hide-button.test.ts:117:23)
  at retry (lib/next-test-utils.ts:942:14)
  at Object.<anonymous> (development/app-dir/dev-indicator/hide-button.test.ts:110:5)
  at Proxy._chain (lib/browsers/playwright.ts:718:23)
  at Proxy._chain (lib/browsers/playwright.ts:694:17)
  at Proxy.continueChain (lib/browsers/playwright.ts:500:17)
  at text (development/app-dir/dev-indicator/hide-button.test.ts:117:65)
  at retry (lib/next-test-utils.ts:942:14)
  at Object.<anonymous> (development/app-dir/dev-indicator/hide-button.test.ts:110:5)

pnpm test-start-turbo test/production/next-server-nft/next-server-nft.test.ts (turbopack) (job)

  • next-server-nft > with adapters > should not trace too many files in next-minimal-server.js.nft.json (DD)
Expand output

● next-server-nft › with adapters › should not trace too many files in next-minimal-server.js.nft.json

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `next-server-nft with adapters should not trace too many files in next-minimal-server.js.nft.json 1`

- Snapshot  - 0
+ Received  + 1

@@ -108,10 +108,11 @@
    "/node_modules/next/dist/server/route-modules/app-page/vendored/contexts/image-config-context.js",
    "/node_modules/next/dist/server/route-modules/app-page/vendored/contexts/router-context.js",
    "/node_modules/next/dist/server/route-modules/app-page/vendored/contexts/server-inserted-html.js",
    "/node_modules/next/dist/server/runtime-reacts.external.js",
    "/node_modules/next/dist/shared/lib/deep-freeze.js",
+   "/node_modules/next/dist/shared/lib/errors/sync-io.js",
    "/node_modules/next/dist/shared/lib/i18n/normalize-locale-path.js",
    "/node_modules/next/dist/shared/lib/invariant-error.js",
    "/node_modules/next/dist/shared/lib/is-plain-object.js",
    "/node_modules/next/dist/shared/lib/is-thenable.js",
    "/node_modules/next/dist/shared/lib/no-fallback-error.external.js",

  590 |         const trace = normalizeNFT(repoRoot, Array.from(files))
  591 |
> 592 |         expect(trace).toMatchInlineSnapshot(`
      |                       ^
  593 |          [
  594 |            "./.next/BUILD_ID",
  595 |            "./.next/app-path-routes-manifest.json",

  at Object.toMatchInlineSnapshot (production/next-server-nft/next-server-nft.test.ts:592:23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant