Skip to content

fix(open-next): allow more status codes for ISR revalidation#1121

Merged
conico974 merged 2 commits intoopennextjs:mainfrom
ntltd:fix/isr-revalidation-status-codes
Mar 30, 2026
Merged

fix(open-next): allow more status codes for ISR revalidation#1121
conico974 merged 2 commits intoopennextjs:mainfrom
ntltd:fix/isr-revalidation-status-codes

Conversation

@ntltd
Copy link
Copy Markdown
Contributor

@ntltd ntltd commented Feb 20, 2026

Allow more status codes for ISR revalidation

Problem

The revalidation handler was checking res.statusCode !== 200 to determine success. This had two issues:

  • Too strict: valid ISR outcomes like redirects (301, 302, 307, 308), Not Found (404), and Gone (410) were incorrectly treated as failures and pushed to failedRecords.
  • Too implicit: 5xx errors were excluded by accident rather than by intent, making the behavior hard to understand and easy to break.

Solution

Replace the !== 200 check with an explicit ALLOWED_STATUSES allowlist:

const ALLOWED_STATUS_CODES = [200, 301, 302, 307, 308, 404, 410]

A revalidation is now only considered successful if both conditions are met:

  • the status code is in ALLOWED_STATUS_CODES
  • the x-nextjs-cache header equals REVALIDATED

Why these status codes?

  • 200 — standard successful page response
  • 301, 302, 307, 308 — redirects are valid ISR outcomes and should not be treated as failures
  • 404 — intentional Not Found pages are a valid cached state in Next.js ISR
  • 410 — Gone, used for pages that have been intentionally removed

Any other status code (notably 5xx errors) will now explicitly mark the record as failed and trigger the existing retry/error reporting logic.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: 07122f0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ntltd ntltd force-pushed the fix/isr-revalidation-status-codes branch 2 times, most recently from 7a60f58 to a53de6a Compare February 20, 2026 08:17
Copy link
Copy Markdown
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a little question about the status code used

}[];
}

const ALLOWED_STATUS_CODES = [200, 301, 302, 307, 308, 404, 410]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Next using the 410 status code? Similar question for 301/302, from what I remember, Next only uses 307/308

Copy link
Copy Markdown
Contributor Author

@ntltd ntltd Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using getServerSideProps, you are able to set a custom status code. For example, on our website, we return a 410 status when content is deactivated.
While it's true that Next.js internally relies only on 307 and 308 status codes, I have included 301 and 302 to ensure full support for all HTTP redirects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry forgot to respond here, page using getServerSideProps does not use ISR revalidation , useless to add anything for them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I’ve updated the logic to include 200, 404, and 307 / 308 status codes. I’ve actually been maintaining a local patch for about a year to handle edge cases where 'bad' 404s or redirects weren't revalidating properly in my app.
I can remove the 410 and 301 / 302 codes if you prefer. My initial goal was to be as exhaustive as possible regarding "allowed" codes, but your points are valid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hesitate to ping me if I don't respond.
If you could drop the 410 and 301/302 that would be great. I don't want to include things that are not Next.js behavior here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done @conico974! Thanks for feedback.

@ntltd ntltd force-pushed the fix/isr-revalidation-status-codes branch from f7b6f12 to 0763a7c Compare March 30, 2026 12:41
@ntltd ntltd force-pushed the fix/isr-revalidation-status-codes branch from 0763a7c to 07122f0 Compare March 30, 2026 12:41
@conico974 conico974 merged commit fad4632 into opennextjs:main Mar 30, 2026
@ntltd ntltd deleted the fix/isr-revalidation-status-codes branch March 30, 2026 15:26
@conico974
Copy link
Copy Markdown
Contributor

Thanks for the PR @ntltd

@github-actions github-actions bot mentioned this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants