File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
packages/nuxt/src/runtime/utils Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import type { NuxtPage } from 'nuxt/schema';
44
55export type NuxtPageSubset = { path : NuxtPage [ 'path' ] ; file : NuxtPage [ 'file' ] } ;
66
7+ const extractionResultCache = new Map < string , null | { parametrizedRoute : string } > ( ) ;
8+
79/**
810 * Extracts route information from the SSR context modules and URL.
911 *
@@ -35,6 +37,15 @@ export function extractParametrizedRouteFromContext(
3537 return null ;
3638 }
3739
40+ const cacheKey = Array . from ( ssrContextModules ) . sort ( ) . join ( '|' ) ;
41+ const cachedResult = extractionResultCache . get ( cacheKey ) ;
42+ if ( cachedResult !== undefined ) {
43+ logger . log ( 'Found cached result for parametrized route:' , currentUrl ) ;
44+ return cachedResult ;
45+ }
46+
47+ logger . log ( 'No parametrized route found in cache lookup. Extracting parametrized route for:' , currentUrl ) ;
48+
3849 const modulesArray = Array . from ( ssrContextModules ) ;
3950
4051 const modulePagePaths = modulesArray . map ( module => {
@@ -55,10 +66,13 @@ export function extractParametrizedRouteFromContext(
5566
5667 // Check if any module of the requested page ends with the same folder/relative path structure as the parametrized filePath from build time.
5768 if ( modulePagePaths . some ( filePath => filePath && normalizedFile . endsWith ( filePath ) ) ) {
58- return { parametrizedRoute : routeData . path } ;
69+ const result = { parametrizedRoute : routeData . path } ;
70+ extractionResultCache . set ( cacheKey , result ) ;
71+ return result ;
5972 }
6073 }
6174 }
6275
76+ extractionResultCache . set ( cacheKey , null ) ;
6377 return null ;
6478}
You can’t perform that action at this time.
0 commit comments