Skip to content

Admin RootLayout passes a server-made viewport element into the client DocumentRoot's <head> — duplicate tag, and it can suspend <head> and break hydration in Next dev #19697

Open

Description

@toddagent01

Describe the Bug

@payloadcms/ui's server RootLayout creates a <meta name="viewport"> React element on the server and passes it as the viewport prop into the client DocumentRoot, which renders it inside <head>:

This causes two problems:

1. The tag is emitted twice. @payloadcms/next's generateViewport adapter (packages/next/src/adapters/viewport.ts) already emits the identical viewport meta through Next's metadata API (same getNextViewport logic, including maximumScale: 1 for iPhone user agents), so a standard admin layout ends up with two <meta name="viewport"> tags.

2. In Next.js 16 development it can suspend <head> during hydration, which trips a React bug and fails hydration of the whole admin. Because the element is created in a server component and rendered by a client component, Next's dev server streams its React debug rows (owner/stack) separately, over the dev websocket. When those rows arrive after hydration has already started, the element is still a blocked Flight chunk, so <head> suspends. React then replays the head fiber, and due to react/react#37551 the replay overwrites the single saved hydration position outside <head> with a node inside <head>. <body> then hydrates against <head>'s nodes: "Hydration failed because the server rendered HTML didn't match the client", and the whole document is client-rendered.

Whether it fires depends on dev-server timing. In one project, a long-running dev server failed almost every load of some admin views (collection create/edit) while other views never failed; a freshly restarted server never failed at all. Production builds have no debug channel and are unaffected.

Reproduction Steps / Evidence

Observed on Payload 4.0.0-beta.6 (@payloadcms/[email protected]), Next.js 16.4.6, react/react-dom 19.3.1, dev server (next dev):

Suggested fix

Drop the viewport prop from RootLayout/DocumentRoot (and the getViewportMeta call), since the Next adapter's generateViewport already emits the same tag. DocumentRoot's own doc comment already points this way ("adapters with router-managed metadata supply it through head"), so an adapter without router-managed viewport metadata could pass it via the existing head prop instead. This removes the duplicate tag and the dev-only <head> suspension regardless of when the React bug is fixed.

Activity

  1. lx3133584 commented on Nov 18, 2026

    @lx3133584

    Opened #19706 for this: dropped the viewport prop from DocumentRoot and the getViewportMeta call from RootLayout. Both adapters already emit the tag, so the admin was shipping it twice; the head prop is unchanged for callers that need something else in <head>. getViewportMeta stays exported — removing a public export is a separate breaking change.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions