next.js: GetStaticProps returning initial notFound never triggers a rebuild on revalidate with dynamic routes
What version of Next.js are you using?
10.0.5
What version of Node.js are you using?
12.13.0
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
next start
Describe the Bug
If getStaticProps
returns notFound: true
in the initial build with a revalidate value, Nextjs never tries to rebuild the page
Expected Behavior
Nextjs should try rebuilding the page instead of assuming permanent 404
To Reproduce
export const getStaticProps = async (props) => {
try {
const dictionaries = await apiFetch();
return {
props: {
dictionaries,
},
revalidate: 60,
};
} catch (error) {
// assume the api fetch fails with the initial build
return {
notFound: true,
props: {
dictionaries: {},
},
revalidate: 60,
};
}
// On subsequent re-builds after revalidate has passed and the api returns a ok response, Nextjs never tries to rebuild the page and always returns the 404 page instead
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 22
- Comments: 21 (5 by maintainers)
Same here, when
{notFound: true}
revalidate doesn’t happen. Is this gonna be fixed soon? It’s pretty big issue. ThanksI am encountering a similar experience (but somewhat in reverse).
The initial static page with a dynamic route is built successfully.
getStaticPaths
uses{fallback: 'blocking'}
andgetStaticProps
uses{revalidate: 1}
. Then then the page data is removed from the db sogetStaticProps
returns{notFound: true}
. Despite all this, the static page continues to be served.I confirmed that the data fetching call that should happen in
getStaticProps
returns no data, so it appears as thoughgetStaticProps
isn’t running at all.Same here, when a page is 404 it never gets rebuilt.
@ijjk You did not satisfy the condition of the bug because when you ran
yarn build
the file contained200
. It has to be the first run that returnsnotFound: true
not one later at some point.We’re experiencing this problem as well. It’s a pretty big issue for us if products are being added to our product catalog that had been a 404 before but won’t revalidate. Would appreciate an update as well. (next v11.0.1)
My mistake. Didn’t added revalidate to return with notFound
I created an other reproduction here: https://github.com/la55u/revalidate-test I cannot deploy it to Vercel due to this bug: https://github.com/vercel/next.js/issues/27948, but here is how to test it locally:
npm run build
npm run start
The important part is that steps 2 & 4 should happen at a time when the minute is even e.g. 11:32, so the notFound will return
true
and the first time you open the page will be 404. Try refreshing the page until the minute is odd and you will still see the 404 page.Thanks for the sandbox @janus-reith, I actually forgot to mention that this happens with dynamic routes, I think how static routes work like in your Sandbox should be the way to go. I made a fork of your sandbox here with dynamic routes. Notice that the
/intl/docs/intl-page
always serves the 404 page even after revalidate time has passed since it errors during build while/us/docs/us-page
page works as intended.