From 50d69bff3a6204d563d5a22da99f1df5c6581e1e Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Wed, 31 Jan 2024 10:54:01 +0100 Subject: [PATCH] fix(nuxt): fix syntax error when serializing route meta (#25515) --- packages/nuxt/src/pages/utils.ts | 2 +- .../pages-override-meta-disabled.test.ts.snap | 10 ++++++++++ .../pages-override-meta-enabled.test.ts.snap | 9 +++++++++ packages/nuxt/test/pages.test.ts | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index 53d4d80238..d3030dc0d5 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -457,7 +457,7 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set = } } else { if (route.meta != null) { - metaRoute.meta = `{ ...(${metaImportName}) || {}), ...${route.meta} }` + metaRoute.meta = `{ ...(${metaImportName} || {}), ...${route.meta} }` } if (route.alias != null) { diff --git a/packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snap b/packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snap index 0960895fa4..d05072877c 100644 --- a/packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snap +++ b/packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snap @@ -1,4 +1,14 @@ { + "pushed route, skips generation from file": [ + { + "alias": "["pushed-route-alias"].concat(mockMeta?.alias || [])", + "component": "() => import("pages/route-file.vue").then(m => m.default || m)", + "meta": "{ ...(mockMeta || {}), ...{"someMetaData":true} }", + "name": "mockMeta?.name ?? "pushed-route"", + "path": "mockMeta?.path ?? "/"", + "redirect": "mockMeta?.redirect", + }, + ], "route without file": [ { "alias": "["sweet-home"]", diff --git a/packages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snap b/packages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snap index 8a89561e83..977956010f 100644 --- a/packages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snap +++ b/packages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snap @@ -1,4 +1,13 @@ { + "pushed route, skips generation from file": [ + { + "alias": "["pushed-route-alias"]", + "component": "() => import("pages/route-file.vue").then(m => m.default || m)", + "meta": "{"someMetaData":true}", + "name": ""pushed-route"", + "path": ""/"", + }, + ], "route without file": [ { "alias": "["sweet-home"]", diff --git a/packages/nuxt/test/pages.test.ts b/packages/nuxt/test/pages.test.ts index 8f09df63c8..dd1c2239ee 100644 --- a/packages/nuxt/test/pages.test.ts +++ b/packages/nuxt/test/pages.test.ts @@ -542,6 +542,18 @@ describe('pages:generateRoutesFromFiles', () => { } ] }, + { + description: 'pushed route, skips generation from file', + output: [ + { + name: 'pushed-route', + path: '/', + alias: ['pushed-route-alias'], + meta: { someMetaData: true }, + file: `${pagesDir}/route-file.vue`, + } + ] + }, ] const normalizedResults: Record = {}