diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index 923348c5a9..b89348ae6e 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -256,13 +256,19 @@ export async function getRouteMeta (contents: string, absolutePath: string): Pro extractedMeta[key] = property.value.value } - const extraneousMetaKeys = pageMetaArgument.properties - .filter(property => property.type === 'Property' && property.key.type === 'Identifier' && !(extractionKeys as unknown as string[]).includes(property.key.name)) - // @ts-expect-error inferred types have been filtered out - .map(property => property.key.name) - - if (extraneousMetaKeys.length) { - dynamicProperties.add('meta') + for (const property of pageMetaArgument.properties) { + if (property.type !== 'Property') { + continue + } + const isIdentifierOrLiteral = property.key.type === 'Literal' || property.key.type === 'Identifier' + if (!isIdentifierOrLiteral) { + continue + } + const name = property.key.type === 'Identifier' ? property.key.name : String(property.value) + if (!(extractionKeys as unknown as string[]).includes(name)) { + dynamicProperties.add('meta') + break + } } if (dynamicProperties.size) { diff --git a/packages/nuxt/test/page-metadata.test.ts b/packages/nuxt/test/page-metadata.test.ts index 4431b80f2f..01d98b9503 100644 --- a/packages/nuxt/test/page-metadata.test.ts +++ b/packages/nuxt/test/page-metadata.test.ts @@ -75,6 +75,28 @@ describe('page metadata', () => { } `) }) + + it('should extract serialisable metadata all quoted', async () => { + const meta = await getRouteMeta(` + + `, filePath) + + expect(meta).toMatchInlineSnapshot(` + { + "meta": { + "__nuxt_dynamic_meta_key": Set { + "meta", + }, + }, + } + `) + }) }) describe('normalizeRoutes', () => {