Comments (2)
I found a temp workaround that loose background cache rebuild for 404.
I create a custom cache handler that return null instead stale value for 404 page:
I create a "temp-fix" branch on my repo: https://github.com/zeckaissue/nextjs-cache-404-status-update/tree/temp-fix
Here is the cache handler get method
async get(key) {
// This could be stored anywhere, like durable storage
const data = cache.get(key)
if(data?.value?.kind === 'PAGE' && data?.value?.status === 404 && data?.lastModified){
let currentTime = Date.now();
let cacheTime = parseInt(data.lastModified);
let deltaTime = Math.round((currentTime - cacheTime) / 1000);
if (deltaTime > parseInt(data.revalidate || 0)) {
cache.delete(key);
return null // <----- here we return null value instead stale value
}
}
return data
}
Here is the complete cache handler
const cache = new Map()
module.exports = class CacheHandler {
constructor(options) {
this.options = options
}
async get(key) {
// This could be stored anywhere, like durable storage
const data = cache.get(key)
if(data?.value?.kind === 'PAGE' && data?.value?.status === 404 && data?.lastModified){
let currentTime = Date.now();
let cacheTime = parseInt(data.lastModified);
let deltaTime = Math.round((currentTime - cacheTime) / 1000);
if (deltaTime > parseInt(data.revalidate || 0)) {
cache.delete(key);
return null // <----- here we return null value instead stale value
}
}
return data
}
async set(key, data, ctx) {
// This could be stored anywhere, like durable storage
cache.set(key, {
value: data,
lastModified: Date.now(),
tags: ctx.tags,
ravalidate: ctx.revalidate,
})
}
async revalidateTag(tag) {
// Iterate over all entries in the cache
for (let [key, value] of cache) {
// If the value's tags include the specified tag, delete this entry
if (value.tags.includes(tag)) {
cache.delete(key)
}
}
}
}
from next.js.
I am facing the same issue. Tried to reproduce this bug with 15.0.0-canary.115 and it seems to be fixed there.
Unfortunately there is an unexpected behavior with 5xx response codes. In this case I would expect that stale cache data is used by nextjs from the cache.
from next.js.
Related Issues (20)
- Next.js bundles libraries only used in Server Components into the Client Bundle Chunks
- [turbo] an unexpected Turbopack error occured HOT 3
- Why the response data is so big in browser when I use the server action with cookies().set or cookies().delete or etc that modify the cookie HOT 2
- NextResponse throws error when http request status code is 204 HOT 1
- BUG: incorrect url encoding in `<link rel="preload">` for prioritized images
- `next/font` interferes with header links from middleware.
- Can't use bcrypt in middleware HOT 4
- It hasn't been resolved for several months. accesstoken reissue issue
- Error and reload during HMR with MUI HOT 1
- Error and reload during HMR with MUI
- Incomplete data from Link prefetch HOT 1
- Server action called from client component is invoked but return data is always undefined (even though network response has data in it) HOT 1
- Failed to build standalone using instrumentationHook
- Next incorrectly infers static builds when using `Promise.prototype.catch` on the dynamic action in a `Page`
- Docs: how to configure lightningcss
- React and Node.js it's time to to declare a final response to these issues once and for all related TypeError's there has been enough issue posts about it already
- Your Team encountered an unknown problem. Please reach out to our support team for details. Learn More HOT 1
- generateStaticParams globalThis (global) singleton problem
- New page is called when intercepting routes are terminated before the server action is completed
- Hot-reloading doesn't work for a newly created directory / files. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.