Skip to content

feat(nuxt): allow setting layout props in definePageMeta#34258

Merged
danielroe merged 6 commits intonuxt:mainfrom
KazariEX:feat/page-meta-layout-props
Feb 6, 2026
Merged

feat(nuxt): allow setting layout props in definePageMeta#34258
danielroe merged 6 commits intonuxt:mainfrom
KazariEX:feat/page-meta-layout-props

Conversation

@KazariEX
Copy link
Copy Markdown
Member

@KazariEX KazariEX commented Feb 6, 2026

🔗 Linked issue

resolve #34241

📚 Description

The API will look like:

definePageMeta({
  layout: {
    name: "center",
    props: {
      foo: "bar",
    },
  },
});

@KazariEX KazariEX requested a review from danielroe as a code owner February 6, 2026 14:40
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 6, 2026

Walkthrough

Extends the public Nuxt PageMeta.layout typing to also accept an object shape { name?: LayoutKey | false, props?: Record<string, any> } (and their MaybeRef/ComputedRef forms) in addition to existing LayoutKey | false. The page-meta compiler transform now recognises a nested layout ObjectExpression, inlines layout.name into layout, extracts layout.props into layoutProps, and removes the original nested properties. Tests and a fixture were added to verify transform output and runtime handling of layout props.

Possibly related PRs

  • nuxt/nuxt PR 33805 — Adds first-class support for layout props and propagates layoutProps through setPageLayout, router and NuxtLayout, targeting the same feature surface.
  • nuxt/nuxt PR 31306 — Modifies the page-meta transform extraction/removal logic and serialisability checks; closely related to the transformer edits here.
  • nuxt/nuxt PR 34248 — Adjusts NuxtLayouts type generation to map layout names to ComponentProps<...> with inline type imports; relevant to the typings changes made.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enabling layout props configuration within definePageMeta.
Description check ✅ Passed The description clearly relates to the changeset, explaining the new API syntax for passing layout names and props via definePageMeta.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #34241: allows passing layout name and props via definePageMeta object syntax, with proper type augmentation and transformation logic.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing layout props support in definePageMeta; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/nuxt/src/pages/plugins/page-meta.ts`:
- Around line 253-285: The layout-object edge case must be handled when layout
has a props field but no name: inside the block handling prop.key.name ===
'layout' (and prop.value.type === 'ObjectExpression'), detect whether any
layoutProp with key.name === 'name' exists; if none, treat the entire layout
property as absent — remove/overwrite the layout property (respecting the same
nextProperty/comma removal logic used earlier) and still appendLeft layoutProps
as `layoutProps: ...` only if present; update the logic around
m.overwrite/m.appendLeft in the layout handling to first scan layoutProp keys,
conditionally remove the parent prop when name is missing, and keep existing
behavior when name exists.

In `@packages/nuxt/test/page-metadata.test.ts`:
- Around line 801-824: Rename the test description string in the it(...) block
from "should transform layout writen in object syntax" to "should transform
layout written in object syntax" and add two small tests alongside it: one SFC
where definePageMeta({ layout: { name: 'foo' } }) and assert the transformed
code yields layout: 'foo' with no layoutProps, and another SFC where
definePageMeta({ layout: { props: { bar: 'bar' } } }) and assert the transformer
(using parse/compileScript and transformPlugin.transform.handler) produces
layoutProps: { bar: 'bar' } and omits a layout string (or produces the expected
malformed-handling behavior), using the same pattern as the existing test to
locate code paths in transformPlugin.transform.handler and compileScript.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 6, 2026

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@34258

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@34258

nuxt

npm i https://pkg.pr.new/nuxt@34258

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@34258

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@34258

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@34258

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@34258

commit: 5ec8e66

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 6, 2026

CodSpeed Performance Report

Merging this PR will improve performance by 15.53%

Comparing KazariEX:feat/page-meta-layout-props (5ec8e66) with main (fff8992)

Summary

⚡ 1 improved benchmark
✅ 9 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
writeTypes in the basic-types fixture 99.4 ms 86 ms +15.53%

@KazariEX KazariEX changed the title feat(nuxt): allow set layout props in definePageMeta feat(nuxt): allow setting layout props in definePageMeta Feb 6, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/nuxt/src/pages/plugins/page-meta.ts`:
- Around line 268-293: The layout-object handling and the extractedKeys branch
can both call omitProp on the same prop causing double MagicString.overwrite;
modify the logic in the loop that processes props so that when prop.key.name ===
'layout' and prop.value.type === 'ObjectExpression' you perform the layout
extraction (appendLeft for name/props) and then skip the extractedKeys check
(e.g., add a continue or a conditional guard) to prevent calling omitProp twice;
reference the functions/identifiers isSerializable, extractedKeys, omitProp, and
the experimental extraPageMetaExtractionKeys option when locating the code to
change.

Comment on lines +639 to +642
' layout?: MaybeRef<LayoutKey | false> | ComputedRef<LayoutKey | false> | {',
' name?: MaybeRef<LayoutKey | false> | ComputedRef<LayoutKey | false>',
' props?: Record<string, any>',
' }',
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems hard to type the props. I think it could be done with a vls plugin (in dxup), but that would limit its widespread adoption.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a look this weekend or later

@danielroe danielroe merged commit 0fa65fc into nuxt:main Feb 6, 2026
97 of 99 checks passed
@github-actions github-actions bot mentioned this pull request Feb 6, 2026
@KazariEX KazariEX deleted the feat/page-meta-layout-props branch February 6, 2026 17:27
@danielroe
Copy link
Copy Markdown
Member

oops, merge this accidentally (it's a patch next, not a minor). I'll revert, and would you mind re-opening? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow in definePageMeta pass props to layout

3 participants