Skip to content
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

fix(nuxt): remove undefined keys in route object #25667

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/nuxt/src/pages/utils.ts
Expand Up @@ -139,8 +139,8 @@
const metaCache: Record<string, Partial<Record<keyof NuxtPage, any>>> = {}
async function getRouteMeta (contents: string, absolutePath: string): Promise<Partial<Record<keyof NuxtPage, any>>> {
// set/update pageContentsCache, invalidate metaCache on cache mismatch
if (!(absolutePath in pageContentsCache) || pageContentsCache[absolutePath] !== contents) {
pageContentsCache[absolutePath] = contents
if (!(absolutePath in pageContentsCache) || pageContentsCache[absolutePath] !== contents) {
pageContentsCache[absolutePath] = contents
delete metaCache[absolutePath]
}

Expand Down Expand Up @@ -183,7 +183,7 @@
try {
extractedMeta[key] = JSON.parse(runInNewContext(`JSON.stringify(${valueString})`, {}))
} catch {
console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not JSON-serializable (reading \`${absolutePath}\`).`)

Check warning on line 186 in packages/nuxt/src/pages/utils.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
dynamicProperties.add(key)
continue
}
Expand All @@ -196,7 +196,7 @@
continue
}
if (element.type !== 'Literal' || typeof element.value !== 'string') {
console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not an array of string literals (reading \`${absolutePath}\`).`)

Check warning on line 199 in packages/nuxt/src/pages/utils.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
dynamicProperties.add(key)
continue
}
Expand All @@ -207,7 +207,7 @@
}

if (property.value.type !== 'Literal' || typeof property.value.value !== 'string') {
console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not a string literal or array of string literals (reading \`${absolutePath}\`).`)

Check warning on line 210 in packages/nuxt/src/pages/utils.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
dynamicProperties.add(key)
continue
}
Expand Down Expand Up @@ -414,6 +414,12 @@
redirect: serializeRouteValue(page.redirect),
}

for (const key of ['path', 'name', 'meta', 'alias', 'redirect'] satisfies NormalizedRouteKeys) {
if (route[key] === undefined) {
delete route[key]
}
}

if (page.children?.length) {
route.children = normalizeRoutes(page.children, metaImports, overrideMeta).routes
}
Expand Down
Expand Up @@ -15,7 +15,6 @@
"meta": "{"hello":"world"}",
"name": ""home"",
"path": ""/"",
"redirect": undefined,
},
],
"should allow pages with `:` in their path": [
Expand Down
Expand Up @@ -14,7 +14,6 @@
"meta": "{"hello":"world"}",
"name": ""home"",
"path": ""/"",
"redirect": undefined,
},
],
"should allow pages with `:` in their path": [
Expand Down