Skip to content

fix(ui): stop RootLayout handing the document its own viewport tag - #19706

Open
lx3133584 wants to merge 2 commits into
payloadcms:mainfrom
lx3133584:fix/drop-duplicate-viewport-meta
Open

lx3133584 wants to merge 2 commits into
payloadcms:mainfrom
lx3133584:fix/drop-duplicate-viewport-meta

Conversation

@lx3133584

Copy link
Copy Markdown

Fixes #19697

Problem

RootLayout built a <meta name="viewport"> element from the request's user agent and passed it to DocumentRoot, which rendered it inside <head>. Every adapter already emits that tag itself — @payloadcms/next through Next's metadata API (generateViewport), @payloadcms/tanstack-start from the route's head() — so the admin shipped it twice.

In Next's dev server the duplicate has a second effect. The element is created in a server component and rendered by a client one, so Next streams its React debug rows separately. When those arrive after hydration has started, <head> suspends, React replays the head fiber, and the saved hydration cursor is overwritten with a node inside <head> — <body> then hydrates against <head>'s nodes and the whole document falls back to client rendering. Production builds have no debug channel and are unaffected.

Fix

Drop the viewport prop from DocumentRoot and the getViewportMeta call from RootLayout. The head prop stays, so anything a caller wants in <head> still goes through the same place.

getViewportMeta remains exported from @payloadcms/ui/layouts and @payloadcms/ui/shared. Removing a public export is a separate, breaking change, so it is left alone here.

Testing

  • Extended packages/ui/src/layouts/Root/index.spec.ts: the spec mounts RootLayout against stubbed layout data, admin context and dependencies, then asserts the element it returns carries no viewport prop. On the unmodified source it fails with the rendered <meta name="viewport" ... /> element as the received value.
  • vitest run --project unit packages/ui: 54 files, 423 passed.
  • oxfmt --check on the three changed files passes; pnpm lint reports nothing in them.

`RootLayout` built a `<meta name="viewport">` element from the request's
user agent and passed it to `DocumentRoot`, which rendered it inside `<head>`.
Every adapter already emits that tag itself: `@payloadcms/next` through
Next's metadata API from `generateViewport`, and `@payloadcms/tanstack-start`
from the route's `head()`. The admin therefore shipped the tag twice.

In Next's dev server the duplicate also has a second effect. The element is
created in a server component and rendered by a client one, so Next streams
its React debug rows separately. When those arrive after hydration has
started, `<head>` suspends, React replays the head fiber, and the saved
hydration cursor is overwritten with a node inside `<head>` — `<body>` then
hydrates against `<head>`'s nodes and the whole document falls back to
client rendering. Production builds have no debug channel and are unaffected.

Drop the prop from `DocumentRoot` and the `getViewportMeta` call from
`RootLayout`; the `head` prop remains for anything a caller wants in there.
`getViewportMeta` stays exported, as removing a public export is a separate
change.

The spec now mounts `RootLayout` against stubbed context and asserts the
element it returns carries no `viewport` prop. On the unmodified source it
fails with the rendered meta element as the received value.

Signed-off-by: Liang Xu <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

RootLayout no longer derives or passes a viewport element to DocumentRoot. DocumentRoot no longer declares or renders a viewport prop. The spec tests that the returned document element has no viewport prop.

Changes: Viewport prop removal

Layer / File(s) Summary
Remove viewport prop from root document flow
packages/ui/src/layouts/Root/DocumentRoot.tsx, packages/ui/src/layouts/Root/index.tsx, packages/ui/src/layouts/Root/index.spec.ts
DocumentRoot no longer declares or renders the viewport prop, and RootLayout no longer derives or passes it. The spec adds a test for the absent prop.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: jacobsfletch, jarrodmflesch, alessiogr

Merge Risk: Minimal · previous review a0bc7

This change removes a duplicate viewport tag that could cause a Next.js development hydration problem. Adapters keep supplying viewport metadata, and the head prop is still available. No merge-blocking risk is apparent.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: RootLayout no longer passes its own viewport meta tag to the document. The changeset removes the viewport prop from DocumentRoot and the getViewportMeta call from Root…
Description check Passed The description matches the changeset. It explains that RootLayout built a viewport meta element that duplicated adapter-provided tags. It describes removing the viewport prop from DocumentRoot and th…
Linked Issues check Passed Issue #19697 requires removing the server-created viewport element from RootLayout and DocumentRoot, and the getViewportMeta call. The diff of packages/ui/src/layouts/Root/index.tsx confirms that the …
Out of Scope Changes check Passed The changes are limited to the viewport removal in packages/ui/src/layouts/Root/index.tsx and DocumentRoot.tsx, and a spec update in packages/ui/src/layouts/Root/index.spec.ts that tests the removal. …
Full details: Title check

Explanation

The title names the main change: RootLayout no longer passes its own viewport meta tag to the document. The changeset removes the viewport prop from DocumentRoot and the getViewportMeta call from RootLayout, so the title matches the change and uses the fix(ui) convention.

Full details: Description check

Explanation

The description matches the changeset. It explains that RootLayout built a viewport meta element that duplicated adapter-provided tags. It describes removing the viewport prop from DocumentRoot and the getViewportMeta call from RootLayout, and it covers the spec change and test results.

Full details: Linked Issues check

Explanation

Issue #19697 requires removing the server-created viewport element from RootLayout and DocumentRoot, and the getViewportMeta call. The diff of packages/ui/src/layouts/Root/index.tsx confirms that the getViewportMeta import and the viewport prop passed to DocumentRoot are removed. The raw summary reports that DocumentRoot.tsx drops the viewport prop and its head rendering, while keeping the head prop. The DocumentRoot.tsx diff could not be read because its blob is missing from the checkout, so that part rests on the AI-generated summary only. The new spec asserts that RootLayout returns no viewport prop. The issue's test expectations are covered by this change. No unmet coding requirement is identified.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the viewport removal in packages/ui/src/layouts/Root/index.tsx and DocumentRoot.tsx, and a spec update in packages/ui/src/layouts/Root/index.spec.ts that tests the removal. The PR keeps the head prop and the public getViewportMeta export, as the issue's suggested scope allows. No unrelated change is identified. The DocumentRoot.tsx diff was not directly readable, so its exact content is taken from the raw summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2f86f77 and a0bc750.

Files selected for processing: 3

  • packages/ui/src/layouts/Root/DocumentRoot.tsx
  • packages/ui/src/layouts/Root/index.spec.ts
  • packages/ui/src/layouts/Root/index.tsx
Files with no reviewable changes: 2

  • packages/ui/src/layouts/Root/DocumentRoot.tsx
  • packages/ui/src/layouts/Root/index.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@jacobsfletch jacobsfletch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removing the duplicate viewport tag makes sense to me, but the test here only asserts that the prop was removed, which is just an implementation choice. So I'd prefer dropping it unless we can reliably test the actual failure.

The test could only show that the prop was gone, not that the document still
gets one viewport tag. That is an implementation choice, and the duplicate it
was guarding against is only observable in a running Next dev server, which
this suite does not start.

The layout change stays: neither the Next adapter nor the TanStack Start
adapter needs a tag from the layout, since both emit one themselves.
@lx3133584

Copy link
Copy Markdown
Author

Agreed — dropped in 4dc4c9a. The test could only show the prop was gone, and the duplicate it guarded against is only observable in a running Next dev server, which this suite doesn't start. The layout change itself is unchanged: neither adapter needs a tag from the layout, since both emit one themselves.

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

None yet

Projects

None yet

2 participants