[PR #1055] [MERGED] fix(shims): match Next metadata merge and Twitter inheritance #1054

Closed
opened 2026-05-06 13:11:45 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1055
Author: @NathanDrake2406
Created: 5/4/2026
Status: Merged
Merged: 5/5/2026
Merged by: @james-elicx

Base: mainHead: fix/metadata-merge-and-twitter-inheritance


📝 Commits (4)

  • fe52be8 fix(shims): deep-merge nested metadata and add OG/Twitter inheritance
  • eb8497b fixup! fix(shims): deep-merge nested metadata and add OG/Twitter inheritance
  • 1e5ad6b chore: address review feedback — clone input, ?? for title, missing test
  • 4b4869d fix(shims): match Next metadata segment replacement

📊 Changes

4 files changed (+413 additions, -5 deletions)

View changed files

📝 packages/vinext/src/server/app-page-head.ts (+5 -0)
📝 packages/vinext/src/shims/metadata.tsx (+146 -3)
📝 tests/app-page-head.test.ts (+20 -0)
📝 tests/features.test.ts (+242 -2)

📄 Description

What this changes

Metadata merging now matches Next.js segment semantics while keeping the useful OpenGraph and Twitter post-processing from this branch.

Nested metadata objects such as openGraph, twitter, icons, alternates, and robots are replaced when a later segment defines the same key. Custom other metadata remains merged across segments, which is the explicit exception in Next's resolver.

The branch also keeps the final metadata post-processing pass so Twitter metadata can inherit from OpenGraph after layouts, pages, and file-based metadata have all been resolved.

Why

The original branch treated most nested metadata objects as shallow-merge targets. That preserved stale parent fields when a child segment supplied a partial object, for example keeping a root OpenGraph image after a page defined only its own OpenGraph title.

Next documents metadata merging as shallow, and the source assigns current segment values for openGraph, twitter, alternates, icons, and robots. Only other is merged with prior metadata.

Approach

  • Removed broad nested-object merge handling.
  • Kept an explicit other merge guarded by the supported custom metadata value shape.
  • Gated Twitter auto-creation behind an existing openGraph object, matching Next's post-processing flow.
  • Kept inheritance for existing OpenGraph and Twitter objects from top-level title and description.
  • Kept post-processing after file-based metadata is applied so generated OG and Twitter image metadata participates in the final pass.

Validation

  • vp test run tests/features.test.ts
  • vp test run tests/app-page-head.test.ts
  • vp check tests/features.test.ts tests/app-page-head.test.ts packages/vinext/src/shims/metadata.tsx
  • Commit hook ran vp check --fix and knip

Risks / follow-ups

No known follow-up for the reviewed issue. This intentionally does not recursively merge nested metadata fields other than the supported other metadata map.

References


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/1055 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 5/4/2026 **Status:** ✅ Merged **Merged:** 5/5/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/metadata-merge-and-twitter-inheritance` --- ### 📝 Commits (4) - [`fe52be8`](https://github.com/cloudflare/vinext/commit/fe52be8ae95073a4e1310dfce1d7e7ae8f2dc6d5) fix(shims): deep-merge nested metadata and add OG/Twitter inheritance - [`eb8497b`](https://github.com/cloudflare/vinext/commit/eb8497b387eb59720be1a7ea1d9ef56c0cdca8fe) fixup! fix(shims): deep-merge nested metadata and add OG/Twitter inheritance - [`1e5ad6b`](https://github.com/cloudflare/vinext/commit/1e5ad6b1e9d6c9e4963f54ccc806960d0766f669) chore: address review feedback — clone input, ?? for title, missing test - [`4b4869d`](https://github.com/cloudflare/vinext/commit/4b4869d4772e50dac523f0052e91c669a8790017) fix(shims): match Next metadata segment replacement ### 📊 Changes **4 files changed** (+413 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/app-page-head.ts` (+5 -0) 📝 `packages/vinext/src/shims/metadata.tsx` (+146 -3) 📝 `tests/app-page-head.test.ts` (+20 -0) 📝 `tests/features.test.ts` (+242 -2) </details> ### 📄 Description ## What this changes Metadata merging now matches Next.js segment semantics while keeping the useful OpenGraph and Twitter post-processing from this branch. Nested metadata objects such as `openGraph`, `twitter`, `icons`, `alternates`, and `robots` are replaced when a later segment defines the same key. Custom `other` metadata remains merged across segments, which is the explicit exception in Next's resolver. The branch also keeps the final metadata post-processing pass so Twitter metadata can inherit from OpenGraph after layouts, pages, and file-based metadata have all been resolved. ## Why The original branch treated most nested metadata objects as shallow-merge targets. That preserved stale parent fields when a child segment supplied a partial object, for example keeping a root OpenGraph image after a page defined only its own OpenGraph title. Next documents metadata merging as shallow, and the source assigns current segment values for `openGraph`, `twitter`, `alternates`, `icons`, and `robots`. Only `other` is merged with prior metadata. ## Approach - Removed broad nested-object merge handling. - Kept an explicit `other` merge guarded by the supported custom metadata value shape. - Gated Twitter auto-creation behind an existing `openGraph` object, matching Next's post-processing flow. - Kept inheritance for existing OpenGraph and Twitter objects from top-level title and description. - Kept post-processing after file-based metadata is applied so generated OG and Twitter image metadata participates in the final pass. ## Validation - `vp test run tests/features.test.ts` - `vp test run tests/app-page-head.test.ts` - `vp check tests/features.test.ts tests/app-page-head.test.ts packages/vinext/src/shims/metadata.tsx` - Commit hook ran `vp check --fix` and `knip` ## Risks / follow-ups No known follow-up for the reviewed issue. This intentionally does not recursively merge nested metadata fields other than the supported `other` metadata map. ## References - Next.js metadata merging docs: https://nextjs.org/docs/app/api-reference/functions/generate-metadata#merging - Next.js metadata resolver: https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/metadata/resolve-metadata.ts --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:45 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1054
No description provided.