-
Notifications
You must be signed in to change notification settings - Fork 303
fix(app-router): pass searchParams to layout generateMetadata #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
james-elicx
merged 3 commits into
cloudflare:main
from
NathanDrake2406:fix/layout-generatemetadata-searchparams
Apr 10, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
477032f
fix(app-router): pass searchParams to layout generateMetadata
NathanDrake2406 cb8051e
test: update entry-templates snapshots for searchParams in layout gen…
NathanDrake2406 15a3067
fix: match Next.js parity for layout generateMetadata searchParams
NathanDrake2406 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/fixtures/app-basic/app/layout-metadata-search/layout.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Parity fixture: layout generateMetadata() must NOT receive searchParams. | ||
| * | ||
| * In Next.js, only page generateMetadata() receives searchParams. Layouts | ||
| * always get undefined. This fixture verifies vinext matches that behavior | ||
| * by asserting the fallback title is produced even when a query string is | ||
| * present in the URL. | ||
| * | ||
| * See: next.js resolve-metadata.ts — `isPage ? { params, searchParams } : { params }` | ||
| */ | ||
|
|
||
| export async function generateMetadata({ | ||
| searchParams, | ||
| }: { | ||
| searchParams?: Promise<{ tab?: string }>; | ||
| }) { | ||
| const sp = searchParams ? await searchParams : undefined; | ||
| const tab = sp?.tab ?? "home"; | ||
| return { | ||
| title: `Layout Section: ${tab}`, | ||
| }; | ||
| } | ||
|
|
||
| export default function LayoutMetadataSearchLayout({ children }: { children: React.ReactNode }) { | ||
| return <div data-testid="layout-metadata-search-layout">{children}</div>; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| export default function LayoutMetadataSearchPage() { | ||||||
| return ( | ||||||
| <main data-testid="layout-metadata-search-page"> | ||||||
| <h1>Layout Metadata Search Test</h1> | ||||||
| <p>This page tests that layout generateMetadata receives searchParams.</p> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This copy is stale after the parity fix — the test now verifies that layout
Suggested change
|
||||||
| </main> | ||||||
| ); | ||||||
| } | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Next.js does not pass
searchParamsto layoutgenerateMetadata(), this fixture tests behavior that diverges from Next.js.Consider either:
generateMetadatatest (testing that the page receivessearchParamscorrectly), or"home"becausesearchParamsis not provided to layouts (matching Next.js behavior).Option 2 would be a useful parity test to prevent future accidental passing of
searchParamsto layouts.