Next.js: Regression of #14740

Created on 5 Aug 2020  路  3Comments  路  Source: vercel/next.js

Bug report

Describe the bug

The work in #14740 has caused a bug when a page errors on the server side

Uncaught TypeError: Cannot read property 'statusCode' of undefined
    at Object.fLxa (index.js:60)
    at t (bootstrap:86)
    at Object.LwBP (next.js:1)
    at t (bootstrap:86)
    at c (bootstrap:45)
    at Array.a [as push] (bootstrap:32)
    at 84f3b8c7222dd2225c268a644154c5ba8e99769e.f6885231c259f16e58e7.js:1

Inspecting the error it's happening with:

if (
  page !== '/404' &&
  !(
    page === '/_error' &&
    hydrateProps &&
    hydrateProps.pageProps.statusCode === '404'
  )
) {
  asPath = delBasePath(asPath)
}

Namely hydrateProps does not have a pageProps at this moment. All it has is initialProps, initialState and isServer

pageProps should be prefixed with initialProps

EG the full line should be

hydrateProps.initialProps.pageProps.statusCode === '404'

To Reproduce

Generate an error server side.

function App() {
    const [s, setS] = useState({});
    const z = useMemo(
        () => ({
            a: s.g.h, //.h is not defined
        }),
        [s.g.h]
    );

Expected behavior

Should not throw an exception here

Screenshots

image

System information

  • OS: macOS
  • Version of Next.js: 9.5.1
  • Version of Node.js: 12.18.2
bug please add a complete reproduction needs investigation

Most helpful comment

@Timer totally fixed it! Thank you!

All 3 comments

Can you please try this on next@canary?

@Timer Thanks Joe! I was just about to submit a PR and then I noticed that #15760 resolves this (I think)

Im going to go to canary and see. I'll close this if so.

@Timer totally fixed it! Thank you!

Was this page helpful?
0 / 5 - 0 ratings