question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ISR page deployed to Vercel does not respect `notFound` if its been previously built

See original GitHub issue

Bug report

Describe the bug

A ISR page, deployed to Vercel, that’s been rendered and cached once will never show a 404 again even if notFound: true is returned from getStaticProps.

To Reproduce

  1. Create a new app using npx create-next-app
  2. Create the page pages/[slug].js looking something like this:
export default function PostTemplate({ post: { title }}) {
  return (
    <h1>{title}</h1>
  )
}

export async function getStaticPaths() {
  return {
    paths: [],
    fallback: "blocking",
  }
}

export async function getStaticProps({ params: { slug } }) {
  const res = await fetch(`https://yourapi.com/posts/${slug}`)
  const post = await res.json()

  return {
    props: {
      post
    },
    notFound: !post, // For this example, let's pretend my API returns a nullish value when a post is missing
    revalidate: 1
  }
}

  1. Deploy to Vercel
  2. Publish a post with the slug my-post
  3. Visit yourdeployment.vercel.app/my-post and the post is successfully rendered
  4. Unpublish the post
  5. Reload the page and get a stale version (expected)
  6. Reload again and you will still get the post even though getStaticProps returned notFound: true during the previous revalidation.

Expected behavior

Im expecting the 404 page to be rendered as the previous revalidation returned notFound: true

Screenshots

N/A

System information

  • OS: macOS
  • Chrome 87
  • Version of Next.js: 10.0.3
  • Version of Node.js: 12.x
  • Deployment: Vercel

Additional context

If i run the same app locally (npm start) and try this, the 404 will get displayed as expected which makes me suspect it might be related to the Vercel platform.

Let me know if you need me to provide an example app or if anything is unclear.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jensonbcommented, Dec 17, 2020

I believe the previously generated page.html is left in .next/server/pages/page.html and not cleared when the page is rebuilt with notFound: true. I’m experiencing the following behavior locally:

  1. next build && next export of a page with notFound: true fails due to .next/server/pages/page.html not existing
  2. remove notFound: true, now we are able to next build && next export
  3. add notFound: true, now we are still able to next build && next export
  4. remove .next/, now we get a failure again when attempting to next build && next export

The issue I’m seeing is that next export is attempting to look for the built html file for a notFound: true page, and then either failing due to it not existing or incorrectly using the old version if it exists.

1reaction
ijjkcommented, Apr 14, 2021

Hi, this should now be fixed! I’m going to close this issue, if you are still experiencing problems with this please reply with additional information and we can investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incremental Static Regeneration – Vercel Docs
Incremental Static Regeneration (ISR) allows you to create or update content without redeploying your site. ISR has three main benefits for developers: ...
Read more >
Next.js custom _error page only works locally - Stack Overflow
js 9.4.4, the custom _error page works on Vercel, but it doesn't appear you can deploy a Next.js app below version 10 on...
Read more >
Remix vs Next.js
Another thing that makes deploying to Vercel great is that their CDN supports it. You might wonder why the Remix port isn't as...
Read more >
Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
If you've never heard about Next.js, it's a framework built on top of React ... This is useful when the page does not...
Read more >
Vercel | Miguel Minoldo
Prevent security issues – users should not be able to canonically access. // the pages/sites folder and its respective contents. if (url.pathname.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found