Repository: next.js
Issue: getInitialProps in _error.js does not detect client-side error
Labels: bug,Pages Router

### Link to the code that reproduces this issue

[codesandbox](https://codesandbox.io/p/devbox/vigilant-resonance-m2wyh6?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clrskzcl700073b6ibesabubi%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clrskzcl700023b6iv36u8k78%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clrskzcl700043b6icvtonjv9%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clrskzcl700063b6ihfmdcou2%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clrskzcl700023b6iv36u8k78%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clrskzcl600013b6imuajy06t%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522id%2522%253A%2522clrskzcl700023b6iv36u8k78%2522%252C%2522activeTabId%2522%253A%2522clrskzcl600013b6imuajy06t%2522%257D%252C%2522clrskzcl700063b6ihfmdcou2%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clrskzcl700053b6ispg3fmn4%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clrskzcl700063b6ihfmdcou2%2522%252C%2522activeTabId%2522%253A%2522clrskzcl700053b6ispg3fmn4%2522%257D%252C%2522clrskzcl700043b6icvtonjv9%2522%253A%257B%2522id%2522%253A%2522clrskzcl700043b6icvtonjv9%2522%252C%2522activeTabId%2522%253A%2522clrsw439p02by3b6ipniro8pp%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clrskzcl700033b6il7c33zm3%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clrsw439p02by3b6ipniro8pp%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clrsw43ig002aeehpdiwtaqze%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D)

### To Reproduce

yarn dev

### Current vs. Expected behavior

Unable to detect error in getInitialProps in file (useEffect) `_error.tsx` when an error occurred on client-side.

```typescript
// index.tsx
useEffect(() => {
    throw new Error("error!");
}, []);
```

```typescript
// _error.tsx
...

Error.getInitialProps = (context) => {
  console.log("getinitialprops: error test");

  const { res, err } = context;
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404;

  return { statusCode };
};
```

The next.js document says that getInitialProp also supports client-side, does it not?
https://nextjs.org/docs/pages/api-reference/functions/get-initial-props

> getInitialProps is an async function that can be added to the default exported React component for the page. It will run on both the server-side and again on the client-side during page transitions. The result of the function will be forwarded to the React component as props.

### Provide environment information

```bash
Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
    Binaries:
      Node: 20.9.0
      npm: 9.8.1
      Yarn: 1.22.19
      pnpm: 8.10.2
    Relevant packages:
      next: 12.3.1
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.1.0
```


### Which area(s) are affected? (Select all that apply)

Data fetching (gS(S)P, getInitialProps)

### Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

### Additional context

_No response_