feat(nuxt): allow setting layout props in definePageMeta#34258
feat(nuxt): allow setting layout props in definePageMeta#34258
definePageMeta#34258Conversation
|
|
WalkthroughExtends the public Nuxt Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging this PR will improve performance by 15.53%Comparing Summary
Performance Changes
|
definePageMetadefinePageMeta
There was a problem hiding this comment.
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.
| ' layout?: MaybeRef<LayoutKey | false> | ComputedRef<LayoutKey | false> | {', | ||
| ' name?: MaybeRef<LayoutKey | false> | ComputedRef<LayoutKey | false>', | ||
| ' props?: Record<string, any>', | ||
| ' }', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I can take a look this weekend or later
|
oops, merge this accidentally (it's a patch next, not a minor). I'll revert, and would you mind re-opening? 🙏 |
🔗 Linked issue
resolve #34241
📚 Description
The API will look like: