Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix fetch cache for subsequent 404 responses #70259

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

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from

Conversation

florianliebig
Copy link

What?

Consuming an API with active fetch cache can return 200 responses at one point which land in the fetch cache. If now subsequent requests of the same route return 404 (e.g. in a webshop an article got deactivated), the fetch cache still returns stale data. More details: #62920

Why?

Patched fetch does the subsequent http call anyways, just the stale data is returned.

How?

Allowing patch-fetch to override existing cache entries with status 404. There might be alternative solutions to this, but I didn't see a method to just remove the cache entry here and returning the new data.

Adding testcase to make multiple http calls in jest where the first call is returning 200 status and the second 404.

Fixes #62920

@ijjk
Copy link
Member

ijjk commented Sep 19, 2024

Allow CI Workflow Run

  • approve CI run for commit: 37a0e35

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@florianliebig
Copy link
Author

@ztanner @ijjk Did you had time to look into this already? Is that testcase sufficient or does it need more to check?

@MVaik
Copy link

MVaik commented May 2, 2025

Had a similar issue but in my case it is a 403 error instead as a page was unpublished in the CMS and anonymous users don't have access.
A good solution would probably need to provide options for busting a specific fetch's cache on error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[App Router -> Caching] Fetch cache is not revalidating for pages that have turned into 404 errors.
3 participants