vercel / next.js

The React Framework
https://nextjs.org
MIT License
127k stars 26.99k forks source link

Server side Error.getInitialProps result cannot be hydrated into client error page #44844

Open tangye1234 opened 1 year ago

tangye1234 commented 1 year ago

Verify canary release

Provide environment information

Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 Binaries: Node: 19.4.0 npm: 9.2.0 Yarn: 1.22.19 pnpm: 7.24.3 Relevant packages: next: 13.1.2 eslint-config-next: 13.1.1 react: 18.2.0 react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Data fetching (gS(S)P, getInitialProps)

Link to the code that reproduces this issue

https://github.com/tangye1234/next.js/tree/fix/render-error-on-page-error/test/integration/render-error-on-page-error/pages

To Reproduce

We need to reproduce it on production build, not dev phase.

next build
next start

browser the localhost, the error page cannot be hydrated properly. the console prints a hydration error(react minify error)

Describe the Bug

The bug is firstly introduced by the bugfix: #21240 That bugfix is to solve the top module error in client render/hydration.

In fact, the renderErrorProps.props?.err can never be existed, which breaks the original intents.

Expected Behavior

  1. do not break the original design, that will use the error.getInitialProps server side result as the hydration props.
  2. if error comes from client not server side, it must call error.getInitialProps in the client side.

Which browser are you using? (if relevant)

Chrome 108

How are you deploying your application? (if relevant)

next start in nodejs

vtassios commented 1 year ago

You can't call getInitialProps in client components. Use getInitialProps inside /app at your page.

tangye1234 commented 1 year ago

Unresolved yet in next@13.1.6

tangye1234 commented 1 year ago

Unresolved yet in 13.2.3

DScheglov commented 1 year ago

Unresolved yet in next@13.2.4

tangye1234 commented 1 year ago

Unresolved yet in 13.3