Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbeec5f5

Browse files
committed
fix: wip - fix for caching issues on catch all routes
1 parentd278f66 commitbeec5f5

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

‎src/run/handlers/cache.cts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
121121
}
122122

123123
privatecaptureCacheTags(cacheValue:NetlifyIncrementalCacheValue|null,key:string){
124+
constrequestContext=getRequestContext()
125+
124126
if(!cacheValue){
125127
return
126128
}
127129

128-
constrequestContext=getRequestContext()
129130
// Bail if we can't get request context
130131
if(!requestContext){
131132
return
@@ -393,7 +394,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
393394

394395
awaitthis.cacheStore.set(key,{ lastModified, value},'blobStore.set')
395396

396-
if(data?.kind==='PAGE'||data?.kind==='PAGES'){
397+
if(!data||data?.kind==='PAGE'||data?.kind==='PAGES'){
397398
constrequestContext=getRequestContext()
398399
if(requestContext?.didPagesRouterOnDemandRevalidate){
399400
// encode here to deal with non ASCII characters in the key

‎src/run/handlers/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default async (
132132
}
133133

134134
setCacheControlHeaders(response,request,requestContext,nextConfig)
135-
setCacheTagsHeaders(response.headers,requestContext)
135+
setCacheTagsHeaders(response.headers,request,requestContext)
136136
setVaryHeaders(response.headers,request,nextConfig)
137137
setCacheStatusHeader(response.headers,nextCache)
138138

‎src/run/headers.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ export const setCacheControlHeaders = (
220220
.log('NetlifyHeadersHandler.trailingSlashRedirect')
221221
}
222222

223-
constcacheControl=headers.get('cache-control')
224223
if(status===404){
225224
if(request.url.endsWith('.php')){
226225
// temporary CDN Cache Control handling for bot probes on PHP files
@@ -241,6 +240,8 @@ export const setCacheControlHeaders = (
241240
}
242241
}
243242

243+
constcacheControl=headers.get('cache-control')
244+
244245
if(
245246
cacheControl!==null&&
246247
['GET','HEAD'].includes(request.method)&&
@@ -273,6 +274,7 @@ export const setCacheControlHeaders = (
273274
['GET','HEAD'].includes(request.method)&&
274275
!headers.has('cdn-cache-control')&&
275276
!headers.has('netlify-cdn-cache-control')&&
277+
!newURL(request.url).pathname.startsWith('/api/')&&
276278
requestContext.usedFsReadForNonFallback
277279
){
278280
// handle CDN Cache Control on static files
@@ -281,13 +283,24 @@ export const setCacheControlHeaders = (
281283
}
282284
}
283285

284-
exportconstsetCacheTagsHeaders=(headers:Headers,requestContext:RequestContext)=>{
285-
if(
286-
requestContext.responseCacheTags&&
287-
(headers.has('cache-control')||headers.has('netlify-cdn-cache-control'))
288-
){
286+
exportconstsetCacheTagsHeaders=(
287+
headers:Headers,
288+
request:Request,
289+
requestContext:RequestContext,
290+
)=>{
291+
if(!headers.has('cache-control')&&!headers.has('netlify-cdn-cache-control')){
292+
return
293+
}
294+
295+
if(requestContext.responseCacheTags){
289296
headers.set('netlify-cache-tag',requestContext.responseCacheTags.join(','))
297+
return
290298
}
299+
300+
constkey=newURL(request.url).pathname
301+
constcacheTag=`_N_T_${key==='/index' ?'/' :encodeURI(key)}`
302+
console.log('setCacheTagsHeaders','netlify-cache-tag',key)
303+
headers.set('netlify-cache-tag',cacheTag)
291304
}
292305

293306
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp