Skip to content

docs: lead with use(browser()) for browser-only rendering - #102401

Merged
icyJoseph merged 9 commits into
canaryfrom
docs/browser-only-rendering
Nov 26, 2026
Merged

icyJoseph merged 9 commits into
canaryfrom
docs/browser-only-rendering

Conversation

@icyJoseph

Copy link
Copy Markdown
Member

What

Updates "Rendering components only in the browser" in the Single-Page Applications guide, plus a pointer from the Lazy Loading guide.

  • Leads with use(browser()) inside a Suspense boundary as the way to render a component only in the browser.
  • Keeps next/dynamic with ssr: false for large components that are not needed when the page loads, where the code splitting is the point.
  • Adds guidance on Largest Contentful Paint and on sizing the fallback.
  • Links the React Suspense caveats for the reveal timing.
  • Drops the useEffect suggestion.

Why

The section presented next/dynamic with ssr: false as the default. That option also code splits, so the component's bundle is requested after hydration, and React.lazy suspends on its first client render. The content then arrives as a retried Suspense boundary, which React reveals at most once every 300ms.

With use(browser()) and a static import nothing suspends in the browser, so the component renders in the same pass that hydrates the page.

Measured on a production build of a small repro (Next.js 16.4.6, React 19.3.0, headless Chrome, medians):

content committed LCP
next/dynamic with ssr: false 303ms 324ms
use(browser()) in <Suspense> 33ms 44ms

On a soft navigation, the next/dynamic version showed its fallback for about 300ms with the chunk already cached. The use(browser()) version rendered the content directly.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 0eef717
View workflow run

@github-actions github-actions Bot added the Documentation Related to Next.js' official documentation. label Nov 26, 2026
@icyJoseph
icyJoseph force-pushed the docs/browser-only-rendering branch from 19c436b to fdb98ac Compare November 26, 2026 00:23
Comment thread docs/01-app/02-guides/lazy-loading.mdx Resolved
@icyJoseph
icyJoseph marked this pull request as ready for review November 26, 2026 00:54
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Code review ?

Vercel Agent Verified Review approved this pull request.
0eef717 • Ran Thu, 26 Nov 2026 10:42:43 GMT • 49.9s • Read the full report ↗

Summary

Docs-only change. The 'Rendering components only in the browser' section of the SPA guide now leads with use(browser()) inside a Suspense boundary. It keeps next/dynamic with ssr: false for keeping a module out of prerendering or lazy loading it, adds LCP and fallback guidance, and the Lazy Loading guide gets a cross-link. Since the earlier reviewed commit, one sentence changed: it now says ssr: false skips both rendering and importing the module on the server. Nothing was run; this is prose, so the review rests on reading and on comparing the claims with the SWC dynamic transform and loadable code.

Checked (3)

     Check Location
Holds The new claim that, with ssr: false, the server skips both rendering the component and importing its module matches the App Router transform.
In dynamic.rs, should_skip_ssr_compile (ssr false, server, non-RSC layer, prefer_esm) replaces the loader with an empty async fn (Turbopack) or require.resolveWeak (webpack).
single-page-applications.mdx:255
Holds The guide still warns that use(browser()) doesn't keep top-level window/document code out of prerendering, and points to next/dynamic.
I read the head's section in full. The third-party-library guidance dropped from the old text is kept here.
single-page-applications.mdx:253
Holds The Lazy Loading cross-link targets an anchor that exists.
The heading '### Rendering components only in the browser' in single-page-applications.mdx produces #rendering-components-only-in-the-browser.
lazy-loading.mdx:74
Review steps

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

@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 cfce5ab and isn’t approving it: this repository’s review rules call for a person’s review. 1 open finding is listed in its review summary and inline. View the full report

@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 6d6d195: no issues found, and the change meets this repository’s review rules. View the full report


Calling `use(browser())` guards the component's render. The component's module is still imported during prerendering, so code that reads `window` or `document` at the top level of a module, as some third-party libraries do, throws before the component renders.

To keep a module out of prerendering, or to lazy load the component's JavaScript, use [`next/dynamic`](/docs/app/guides/lazy-loading#nextdynamic) with `ssr: false`. It uses `React.lazy` with the dynamic `import()` you pass, so the browser downloads the JavaScript only when the component renders, and `ssr: false` skips the import on the server:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

...and ssr: false skips the import on the server:

Right, we don't import/evaluate the module, but it also it is the lever to skip rendering — as phrased it is technically correct, you can't render if you don't even load the module, but do humans understand that layering?

@github-actions github-actions Bot added the created-by: Next.js team PRs by the Next.js team. label Nov 26, 2026
@icyJoseph
icyJoseph merged commit 29c0ed0 into canary Nov 26, 2026
60 checks passed
@icyJoseph
icyJoseph deleted the docs/browser-only-rendering branch November 26, 2026 14:57
icyJoseph added a commit that referenced this pull request Nov 26, 2026
#102461)

Backports [docs: lead with use(browser()) for browser-only rendering
(#102401)](#102401) to
`releases/lts/active`.

Cherry-picked from 29c0ed0 with `git
cherry-pick -x`; it applied cleanly with no conflicts.

<!-- NEXT_JS_LLM -->
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 -->
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