Request: Built-in support for returning HTTP 503 in Next.js App Router #77342
Unanswered
yuyake0084
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
I am building a service that displays various types of content. Many content holders manage their own content, and in some cases, they may temporarily choose to hide their content details.
In such cases, a separate system's API responds with an HTTP 503 status. Ideally, Next.js should also return a 503 response to crawlers when it receives this status. However, in the App Router, there is no built-in way to return an HTTP 503 status. Currently, if an internal 5xx error occurs, Next.js automatically returns a 500 status, which is not always appropriate.
For SEO and proper indexing, it is important to return a 503 status instead of 500 when content is temporarily unavailable due to the content holder's decision. However, there is no straightforward way to achieve this in the App Router. I have explored several potential solutions, but none of them provide an optimal approach.
Attempted Solutions
To solve this issue, I have considered various approaches, but ultimately, I found only two possible solutions:
1. Use
middleware.tswith Node.js runtime2. Switch to the Pages Router
Both solutions have drawbacks: middleware increases API load, while switching to the Pages Router requires rewriting a significant portion of the application.
Feature Request
I would like Next.js to provide a built-in way to return an HTTP 503 status in the App Router. This would help handle temporary content unavailability in a more efficient and SEO-friendly way, without the need for workarounds that introduce additional complexity or performance overhead.
Proposal
I propose introducing an experimental feature similar to
authInterrupts, such asserverErrorInterrupts. This would allow developers to enable enhanced server-side error handling, including the ability to return HTTP 503 responses in the App Router.In addition, providing a function like serviceUnavailable() that sets a 503 status while rendering error.tsx would be extremely useful. This would allow developers to properly return a 503 status inside Server Components without complex workarounds.
References
Alternative Solutions
If there is a simpler way to achieve this without introducing a new experimental feature, I would love to hear about it!
I appreciate your feedback and guidance.
Beta Was this translation helpful? Give feedback.
All reactions