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';
4
4
5
5
export type NuxtPageSubset = { path : NuxtPage [ 'path' ] ; file : NuxtPage [ 'file' ] } ;
6
6
7
+ const extractionResultCache = new Map < string , null | { parametrizedRoute : string } > ( ) ;
8
+
7
9
/**
8
10
* Extracts route information from the SSR context modules and URL.
9
11
*
@@ -35,6 +37,15 @@ export function extractParametrizedRouteFromContext(
35
37
return null ;
36
38
}
37
39
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
+
38
49
const modulesArray = Array . from ( ssrContextModules ) ;
39
50
40
51
const modulePagePaths = modulesArray . map ( module => {
@@ -55,10 +66,13 @@ export function extractParametrizedRouteFromContext(
55
66
56
67
// Check if any module of the requested page ends with the same folder/relative path structure as the parametrized filePath from build time.
57
68
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 ;
59
72
}
60
73
}
61
74
}
62
75
76
+ extractionResultCache . set ( cacheKey , null ) ;
63
77
return null ;
64
78
}
You can’t perform that action at this time.
0 commit comments