Skip to content

Commit

Permalink
perf(nuxt): use single iteration when normalising routes (#24946)
Browse files Browse the repository at this point in the history
  • Loading branch information
GalacticHypernova committed Dec 29, 2023
1 parent 34b5299 commit e084ee7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,12 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
return {
imports: metaImports,
routes: genArrayFromRaw(routes.map((page) => {
const route = Object.fromEntries(
Object.entries(page)
.filter(([key, value]) => key !== 'file' && (Array.isArray(value) ? value.length : value))
.map(([key, value]) => [key, JSON.stringify(value)])
) as Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string }
const route: Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string } = Object.create(null)
for (const [key, value] of Object.entries(page)) {
if (key !== 'file' && (Array.isArray(value) ? value.length : value)) {
route[key as Exclude<keyof NuxtPage, 'file'>] = JSON.stringify(value)
}
}

if (page.children?.length) {
route.children = normalizeRoutes(page.children, metaImports).routes
Expand Down

0 comments on commit e084ee7

Please sign in to comment.