Skip to content

Commit 4cf7b2f

Browse files
committed
fix: also target 404 pages when purging cache
1 parent de960f4 commit 4cf7b2f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/run/handlers/cache.cts

+14-5
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
271271
}
272272

273273
this.captureResponseCacheLastModified(blob, key, span)
274-
this.captureCacheTags(blob.value, key)
274+
275+
// Next sets a kind/kindHint and fetchUrl for data requests, however fetchUrl was found to be most reliable across versions
276+
const isDataRequest = Boolean(context.fetchUrl)
277+
if (!isDataRequest) {
278+
this.captureCacheTags(blob.value, key)
279+
}
275280

276281
switch (blob.value?.kind) {
277282
case 'FETCH':
@@ -391,13 +396,17 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
391396

392397
const value = this.transformToStorableObject(data, context)
393398

394-
// if previous CacheHandler.get call returned null (page was either never rendered or was on-demand revalidated)
395-
// and we didn't yet capture cache tags, we try to get cache tags from freshly produced cache value
396-
this.captureCacheTags(value, key)
399+
// Next sets a fetchCache and fetchUrl for data requests, however fetchUrl was found to be most reliable across versions
400+
const isDataReq = Boolean(context.fetchUrl)
401+
if (!isDataReq) {
402+
// if previous CacheHandler.get call returned null (page was either never rendered or was on-demand revalidated)
403+
// and we didn't yet capture cache tags, we try to get cache tags from freshly produced cache value
404+
this.captureCacheTags(value, key)
405+
}
397406

398407
await this.cacheStore.set(key, { lastModified, value }, 'blobStore.set')
399408

400-
if (!data || data?.kind === 'PAGE' || data?.kind === 'PAGES') {
409+
if ((!data && !isDataReq) || data?.kind === 'PAGE' || data?.kind === 'PAGES') {
401410
const requestContext = getRequestContext()
402411
if (requestContext?.didPagesRouterOnDemandRevalidate) {
403412
// encode here to deal with non ASCII characters in the key

0 commit comments

Comments
 (0)