Skip to content

Commit a0d3581

Browse files
committed
Fix client-side errors caused by cached prefetch requests
1 parent 1e6af5f commit a0d3581

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cache.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,24 @@ module.exports = [
111111
expiration: {
112112
maxEntries: 32,
113113
maxAgeSeconds: 24 * 60 * 60 // 24 hours
114-
}
114+
},
115+
plugins: [
116+
{
117+
cacheWillUpdate: async ({ request, response }) => {
118+
if (request.headers.get('x-middleware-prefetch') || response.headers.get('x-middleware-skip')) return null
119+
if (response.status === 200) {
120+
return response
121+
}
122+
return null
123+
}
124+
},
125+
{
126+
cachedResponseWillBeUsed: async ({ cacheName, request, matchOptions, cachedResponse, event }) => {
127+
if (cachedResponse && cachedResponse.headers.get('x-middleware-skip')) return null
128+
return cachedResponse
129+
}
130+
},
131+
],
115132
}
116133
},
117134
{

0 commit comments

Comments
 (0)