fix: improve warning message for _error page during static export #88227
+19
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR improves the confusing warning message that appears when using a custom
_errorpage during static export (next export).Changes:
packages/next/src/server/render.tsx: Add a specific warning message for_errorpagesgetStaticPropsfor all pages_errorpages, references the documentation that statesgetStaticPropsis not supported and recommends using404.jsor500.jsinsteaddocs/02-pages/03-building-your-application/01-routing/08-custom-error.mdx: Enhance documentationgetStaticPropsmay technically compile in_error, it has limitationsWhy?
Currently, when running
next exportwith a custom_errorpage that usesgetInitialProps, Next.js displays a warning recommending the use ofgetStaticProps. However, according to the documentation,_errorpages do not supportgetStaticProps, which causes confusion for developers.Problem:
_errorpage withgetInitialProps→ warning appearsgetStaticPropsgetStaticPropsis not supported in_errorpagesHow?
Warning message branching:
pathname === '/_error'_errorpages do not supportgetStaticProps404.jsor500.jsas alternativesDocumentation enhancement:
getStaticPropsin the Caveats section