Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page not revalidated when fetch no longer returns 404 #73973

Closed
joostmeijles opened this issue Dec 16, 2024 · 7 comments · Fixed by #74577
Closed

Page not revalidated when fetch no longer returns 404 #73973

joostmeijles opened this issue Dec 16, 2024 · 7 comments · Fixed by #74577
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@joostmeijles
Copy link
Contributor

joostmeijles commented Dec 16, 2024

Link to the code that reproduces this issue

https://github.com/joostmeijles/cache-revalidate-404-issue

To Reproduce

  1. Set item value by performing a POST call to http://localhost:3000/set-item with body:
{
  "item": "example value"
}
  1. Visit http://localhost:3000 → page correctly displays actual data
  2. Unset item value by performing a POST call to http://localhost:3000/set-item with body
{
  "item": null
}
  1. Verify that a 404 is returned by visiting http://localhost:3000/get-item
  2. Revalidate the data cache by performing a POST call to http://localhost:3000/revalidate
  3. Visit http://localhost:3000 → page shows a 404
  4. Set item value by performing a POST call to http://localhost:3000/set-item with body:
{
  "item": "example value"
}
  1. Revalidate the data cache by performing a POST call to http://localhost:3000/revalidate
  2. Visit http://localhost:3000 → page wrongly displays 404

Current vs. Expected behavior

The page is not revalidated after the underlying cached fetch value was updated and cached item revalidated. Revalidation has no effect on this. I expect the page to be regenerated when the cached value is revalidated.

Details

The rendered page retrieves the data from the backend using a fetch call. The fetch call has the following properties set:

const res = await fetch(`https://${process.env.VERCEL_URL}/get-item`, {
    cache: 'force-cache',
    next: {
      tags: ['my-cachetag']
    }
  });

After the page rendered a 404 cache revalidation no longer works, i.e. the page is never re-rendered.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Enterprise
  Available memory (MB): 32472
  Available CPU cores: 16
Binaries:
  Node: 18.20.2
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 9.9.0
Relevant Packages:
  next: 15.1.1-canary.6 // Latest available version is detected (15.1.1-canary.6).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

This can be reproduced locally in production mode by npm run build and npm run start.

NB. Set VERCEL_URL="cache-revalidate-404-issue.vercel.app" in your env for the page pre-render to work.

@joostmeijles joostmeijles added the bug Issue was opened via the bug report template. label Dec 16, 2024
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Dec 16, 2024
@fikrikarim
Copy link
Contributor

fikrikarim commented Dec 17, 2024

I'm having the same issue. It's driving me a bit crazy since I've been debugging this issue for a whole day. I thought the problem was in our Next.js app or in our library.

My conclusion: revalidateTag() does not work on 404. revalidatePath does work.

Repo: https://github.com/fikrikarim/nextjs-revalidate-tag-404-bug

Live link: https://revalidate-tag-404-bug.vercel.app/

revalidation-404-bug-small.mp4

@fikrikarim
Copy link
Contributor

Might be related: #66540

@eps1lon
Copy link
Member

eps1lon commented Jan 7, 2025

Created a smaller repro that doesn't require Redis or any VERCEL_URL: https://github.com/eps1lon/cache-revalidate-404-issue. May not work when deployed but that doesn't seem important since it already repros locally with next start.

Bisected with my repro and found that revalidateTag was not sufficient up until 14.3.0-canary.73. 14.3.0-canary.74 fixed it and then we regressed again in 15.0.0-canary.183

@joostmeijles
Copy link
Contributor Author

May be solved by #74577?

@ijjk ijjk closed this as completed in 51e091d Jan 7, 2025
ijjk added a commit that referenced this issue Jan 7, 2025
This ensures we don't lose tags added to a page before `notFound()` is
called as otherwise a fetch on the page that has been revalidated won't
be able to be applied correctly if dropped from a `notFound()` call.
This was broken recently in the refactors of handling rendering in
app-render as it worked correctly in `v14`.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04V3E1UYNQ/p1736200963684869)

Closes https://linear.app/vercel/issue/ENET-1381
Closes https://linear.app/vercel/issue/NEXT-3946
Closes #73973
Closes #66540
@joostmeijles
Copy link
Contributor Author

Confirming that this is solved by upgrading to NextJS v15.1.4: joostmeijles/cache-revalidate-404-issue@4dc962c

@fikrikarim
Copy link
Contributor

I also confirm that this solves the issue in our project

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants