[PR #518] [MERGED] Fix next/head key deduplication #640

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/518
Author: @NathanDrake2406
Created: 3/13/2026
Status: Merged
Merged: 3/13/2026
Merged by: @james-elicx

Base: mainHead: fix/next-head-key-dedup


📝 Commits (4)

  • 7628bb9 Fix next/head key deduplication
  • c1dc8da Fix multi-child next/head deduplication
  • d824574 Align next/head key normalization with Next.js
  • b04be19 Merge upstream/main into fix/next-head-key-dedup

📊 Changes

6 files changed (+310 additions, -69 deletions)

View changed files

📝 packages/vinext/src/shims/head-state.ts (+8 -7)
📝 packages/vinext/src/shims/head.ts (+178 -51)
📝 packages/vinext/src/shims/unified-request-context.ts (+2 -2)
📝 tests/fixtures/pages-basic/pages/isr-second-render-state.tsx (+1 -1)
📝 tests/head.test.ts (+113 -0)
📝 tests/unified-request-context.test.ts (+8 -8)

📄 Description

Summary

  • reduce all mounted next/head children through a shared reducer for both SSR and client updates
  • preserve React key scoping for nested arrays by flattening with React.Children.toArray()
  • stop rewriting raw head keys so distinct user keys containing $ are not collapsed

Why

The previous shim appended tags per Head instance, so keyed deduplication could not match Next.js behavior. The first pass at fixing that also introduced an array-flattening regression by bypassing React key scoping and a key-normalization collision for raw keys containing $.

Testing

  • pnpm test tests/head.test.ts
  • pnpm test tests/pages-router.test.ts -t "renders next/head tags in SSR HTML <head>"
  • pnpm run typecheck
  • pre-commit hook also reran format, tests/head.test.ts, lint, and typecheck successfully

🔄 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/518 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/13/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/next-head-key-dedup` --- ### 📝 Commits (4) - [`7628bb9`](https://github.com/cloudflare/vinext/commit/7628bb9dd14d23e82b390e3bea21d6b38a031394) Fix next/head key deduplication - [`c1dc8da`](https://github.com/cloudflare/vinext/commit/c1dc8da9455a89932faaf1ce2ab68bb6f5f54720) Fix multi-child next/head deduplication - [`d824574`](https://github.com/cloudflare/vinext/commit/d8245749e8b58c802104c562841c56999f84030a) Align next/head key normalization with Next.js - [`b04be19`](https://github.com/cloudflare/vinext/commit/b04be190bc23735ccbe074d02a8012c09e41c4cd) Merge upstream/main into fix/next-head-key-dedup ### 📊 Changes **6 files changed** (+310 additions, -69 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/head-state.ts` (+8 -7) 📝 `packages/vinext/src/shims/head.ts` (+178 -51) 📝 `packages/vinext/src/shims/unified-request-context.ts` (+2 -2) 📝 `tests/fixtures/pages-basic/pages/isr-second-render-state.tsx` (+1 -1) 📝 `tests/head.test.ts` (+113 -0) 📝 `tests/unified-request-context.test.ts` (+8 -8) </details> ### 📄 Description ## Summary - reduce all mounted `next/head` children through a shared reducer for both SSR and client updates - preserve React key scoping for nested arrays by flattening with `React.Children.toArray()` - stop rewriting raw head keys so distinct user keys containing `$` are not collapsed ## Why The previous shim appended tags per `Head` instance, so keyed deduplication could not match Next.js behavior. The first pass at fixing that also introduced an array-flattening regression by bypassing React key scoping and a key-normalization collision for raw keys containing `$`. ## Testing - `pnpm test tests/head.test.ts` - `pnpm test tests/pages-router.test.ts -t "renders next/head tags in SSR HTML <head>"` - `pnpm run typecheck` - pre-commit hook also reran format, `tests/head.test.ts`, lint, and typecheck successfully --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:15 +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#640
No description provided.