developit / developit/nextjs-preact-demo

Render is unexpectedly retried multiple times in case of an exception

Open
#30 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
381
Forks
21
PR merge metrics
No merged PRs in 30d

Description

This issue is probably wrong in this repo, but I am not sure where to put it. So It is not clear to me, if this is a setup problem, e Next.js issue, or a Preact (compat) thing.

When an exception is thrown while rendering a component, there seems to be some retry logic going on, causing multiple subsequently failing renders. I created a page which intentionnaly fails when clicking the "Fail" link:

```jsx
/// pages/failing.js
import Link from 'next/link'

const Failing = ({ query }) => (


Trouble



Fail

{query.fail ? {window.foo.click()} : null}

)

Failing.getInitialProps = async (ctx) => {
console.log('gip')
return {
query: ctx.query,
}
}

export default Failing
```

# Reproduce:
1. Visit [deployed minimal example](https://nextjs-preact-error.lipp.vercel.app/failing)
2. Open Devtools
3. Click Fail link

# What I expect (and what is happening with vanilla React + Next.js):
On console:
- 1x `Page getInitialProps`
- 1x `render page`
- 1x `...TypeError: Cannot read property 'click' of undefined...`
- 1x `ErrorPage getInitialProps`
- 1x `render ErrorPage`

On screen:
- Old page gets "removed"
- Error page gets rendered instead

# What happens:
On console:
- 1x `Page getInitialProps`
- 1x `render page`
- **4x** `...TypeError: Cannot read property 'click' of undefined...`
- **4x** `ErrorPage getInitialProps`
- **5x** `render ErrorPage`
- **1x** `... Uncaught (in promise) Error: Cancel rendering route`

On screen:
- Old page "stays"
- Error page gets rendered additionally

What I find interesting: `render page` is outputted once, while the error is reported 4 times.

# Source of example

This is the [source of the example](https://github.com/lipp/nextjs-preact-demo/tree/error-test), deployed [here](https://nextjs-preact-error.lipp.vercel.app/failing)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.