Repository navigation
Conversation
`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]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
jacobsfletch
left a comment
There was a problem hiding this comment.
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.
|
Agreed — dropped in |
Fixes #19697
Problem
RootLayoutbuilt a<meta name="viewport">element from the request's user agent and passed it toDocumentRoot, which rendered it inside<head>. Every adapter already emits that tag itself —@payloadcms/nextthrough Next's metadata API (generateViewport),@payloadcms/tanstack-startfrom the route'shead()— 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
viewportprop fromDocumentRootand thegetViewportMetacall fromRootLayout. Theheadprop stays, so anything a caller wants in<head>still goes through the same place.getViewportMetaremains exported from@payloadcms/ui/layoutsand@payloadcms/ui/shared. Removing a public export is a separate, breaking change, so it is left alone here.Testing
packages/ui/src/layouts/Root/index.spec.ts: the spec mountsRootLayoutagainst stubbed layout data, admin context and dependencies, then asserts the element it returns carries noviewportprop. 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 --checkon the three changed files passes;pnpm lintreports nothing in them.