mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #376] [MERGED] fix: pass parent promise to generateMetadata() for ancestor metadata access #523
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#523
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/376
Author: @james-elicx
Created: 3/9/2026
Status: ✅ Merged
Merged: 3/9/2026
Merged by: @james-elicx
Base:
main← Head:fix/generatemetadata-parent-parameter📝 Commits (7)
98d70f9fix: pass parent promise to generateMetadata() for ancestor metadata accessd2a91e8regen snapsbf6680efix: address review comments — remove dead array, pass searchParams to generateMetadatae41c0fbregen snaps2b7b2e9regen snaps723b768fix: pass actual route params to layout generateMetadata() in fallback render0147833fix: forward params to resolveModuleViewport in renderHTTPAccessFallbackPage📊 Changes
9 files changed (+765 additions, -156 deletions)
View changed files
📝
packages/vinext/src/server/app-dev-server.ts(+79 -22)📝
packages/vinext/src/shims/metadata.tsx(+9 -2)📝
tests/__snapshots__/entry-templates.test.ts.snap(+474 -132)📝
tests/fixtures/app-basic/app/nextjs-compat/layout-params-notfound/[slug]/layout.tsx(+26 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/metadata-generate-searchparams/page.tsx(+17 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/metadata-parent-generate/layout.tsx(+15 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/metadata-parent-generate/page.tsx(+24 -0)📝
tests/nextjs-compat/metadata.test.ts(+58 -0)📝
tests/nextjs-compat/not-found.test.ts(+63 -0)📄 Description
Summary
Fixes #375 —
generateMetadata()was never passed theparentparameter, causing any app that usesawait parentto throw a TypeError.What changed
shims/metadata.tsx—resolveModuleMetadata()now accepts aparent: Promise<Metadata>parameter (defaults toPromise.resolve({})) and passes it as the second argument tomod.generateMetadata().server/app-dev-server.ts— Both call sites (buildPageElementandrenderHTTPAccessFallbackPage) now build a serial parent promise chain matching Next.js's eager-execution-with-serial-resolution approach:generateMetadata()calls are kicked off concurrently (good for I/O-bound work).parentpromise only resolves after the preceding segment's metadata is merged, soawait parentgives the correct accumulated ancestor metadata.Tests
Three new regression tests in
tests/nextjs-compat/metadata.test.ts, backed by a new fixture attests/fixtures/app-basic/app/nextjs-compat/metadata-parent-generate/:should pass parent metadata to generateMetadata via parent parameter— OG images from parent layout are visible to childshould render page title from generateMetadata that uses parent— page title rendered correctly when using parentparent parameter should not be undefined (await parent must not throw)—await parentnever throwsRoot cause of the previous crash (all tests 500ing)
The initial implementation accidentally included TypeScript type annotations (
Promise<Metadata>[]) inside the template-literal string that generates the virtual RSC entry module. That virtual module is resolved as plain JavaScript (no.tsextension), so the generic syntax caused a parse error, crashing every page request. The fix was to remove the type annotations from the generated code (they're only needed in the outer.tsfile, not in the emitted JS string).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.