File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
packages/open-next/src/core/routing Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @opennextjs/aws " : patch
3
+ ---
4
+
5
+ decode path params in cache interceptor
Original file line number Diff line number Diff line change @@ -129,6 +129,28 @@ async function generateResult(
129
129
} ,
130
130
} ;
131
131
}
132
+ /**
133
+ *
134
+ * SSG cache key needs to be decoded, but some characters needs to be properly escaped
135
+ * https://github.com/vercel/next.js/blob/34039551d2e5f611c0abde31a197d9985918ad
8000
af/packages/next/src/server/lib/router-utils/decode-path-params.ts#L11-L26
136
+ */
137
+ function decodePathParams ( pathname : string ) : string {
138
+ return pathname
139
+ . split ( "/" )
140
+ . map ( ( segment ) => {
141
+ try {
142
+ // https://github.com/vercel/next.js/blob/34039551d2e5f611c0abde31a197d9985918adaf/packages/next/src/shared/lib/router/utils/escape-path-delimiters.ts#L2-L10
143
+ return decodeURIComponent ( segment ) . replace (
144
+ / ( [ \/ # ? ] | % ( 2 f | 2 3 | 3 f | 5 c ) ) / gi,
145
+ ( char : string ) => encodeURIComponent ( char ) ,
146
+ ) ;
147
+ } catch ( e ) {
148
+ // If decodeURIComponent fails, we return the original segment
149
+ return segment ;
150
+ }
151
+ } )
152
+ . join ( "/" ) ;
153
+ }
132
154
133
155
export async function cacheInterceptor (
134
156
event : InternalEvent ,
@@ -147,6 +169,9 @@ export async function cacheInterceptor(
147
169
// We also need to remove trailing slash
148
170
localizedPath = localizedPath . replace ( / \/ $ / , "" ) ;
149
171
172
+ // Then we decode the path params
173
+ localizedPath = decodePathParams ( localizedPath ) ;
174
+
150
175
debug ( "Checking cache for" , localizedPath , PrerenderManifest ) ;
151
176
152
177
const isISR =
You can’t perform that action at this time.
0 commit comments