[PR #500] [MERGED] fix: serve metadata routes in dynamic segments #622

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

📋 Pull Request Information

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

Base: mainHead: fix/metadata-routes-dynamic-segments


📝 Commits (2)

  • 264cb30 fix: serve metadata routes in dynamic segments (opengraph-image, icon, etc.)
  • f157a38 fix: address review — scope patternParts to dynamic routes, fix indentation

📊 Changes

4 files changed (+349 additions, -232 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+68 -34)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+246 -198)
📝 tests/app-router.test.ts (+27 -0)
tests/fixtures/app-basic/app/blog/[slug]/opengraph-image.tsx (+8 -0)

📄 Description

Summary

  • Metadata routes (opengraph-image, icon, twitter-image, etc.) inside dynamic segments returned 404
  • e.g., app/blog/[slug]/opengraph-image.tsx → requesting /blog/hello-world/opengraph-image → 404
  • Root cause: runtime matching used strict equality (cleanPathname === metaRoute.servedUrl) but servedUrl contains literal bracket notation (/blog/[slug]/opengraph-image)
  • Additionally, params were never passed to the metadata function — Next.js passes { params } so the function can generate per-page images

Fix

  • At code-gen time, detect dynamic segments in servedUrl and generate patternParts (reusing the existing matchPattern() function already used for intercept routes)
  • At runtime, use matchPattern() for metadata routes with patternParts to extract params
  • Pass extracted params to the metadata function via makeThenableParams(), matching Next.js behavior

Test plan

  • Scanner test: scanMetadataFiles discovers opengraph-image in dynamic segments
  • Integration test: /blog/hello-world/opengraph-image returns 200 with correct params
  • Integration test: different param values produce different responses
  • All existing metadata route tests still pass (20/20)
  • Entry template snapshots updated
  • CI: full Vitest + Playwright suite

🔄 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/500 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/12/2026 **Status:** ✅ Merged **Merged:** 3/12/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/metadata-routes-dynamic-segments` --- ### 📝 Commits (2) - [`264cb30`](https://github.com/cloudflare/vinext/commit/264cb301a470289350a323545545d484142ae4bd) fix: serve metadata routes in dynamic segments (opengraph-image, icon, etc.) - [`f157a38`](https://github.com/cloudflare/vinext/commit/f157a38134d117ceadce36e4bf82927886110b35) fix: address review — scope patternParts to dynamic routes, fix indentation ### 📊 Changes **4 files changed** (+349 additions, -232 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+68 -34) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+246 -198) 📝 `tests/app-router.test.ts` (+27 -0) ➕ `tests/fixtures/app-basic/app/blog/[slug]/opengraph-image.tsx` (+8 -0) </details> ### 📄 Description ## Summary - Metadata routes (opengraph-image, icon, twitter-image, etc.) inside dynamic segments returned 404 - e.g., `app/blog/[slug]/opengraph-image.tsx` → requesting `/blog/hello-world/opengraph-image` → 404 - Root cause: runtime matching used strict equality (`cleanPathname === metaRoute.servedUrl`) but `servedUrl` contains literal bracket notation (`/blog/[slug]/opengraph-image`) - Additionally, params were never passed to the metadata function — Next.js passes `{ params }` so the function can generate per-page images ## Fix - At code-gen time, detect dynamic segments in `servedUrl` and generate `patternParts` (reusing the existing `matchPattern()` function already used for intercept routes) - At runtime, use `matchPattern()` for metadata routes with `patternParts` to extract params - Pass extracted params to the metadata function via `makeThenableParams()`, matching Next.js behavior ## Test plan - [x] Scanner test: `scanMetadataFiles` discovers opengraph-image in dynamic segments - [x] Integration test: `/blog/hello-world/opengraph-image` returns 200 with correct params - [x] Integration test: different param values produce different responses - [x] All existing metadata route tests still pass (20/20) - [x] Entry template snapshots updated - [ ] CI: full Vitest + Playwright suite --- <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:09 +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#622
No description provided.