Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render is unexpectedly retried multiple times in case of an exception #30

Open
lipp opened this issue Oct 27, 2020 · 1 comment
Open

Comments

@lipp
Copy link

lipp commented Oct 27, 2020

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:

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

const Failing = ({ query }) => (
  <div>
    <h1>Trouble</h1>
    <Link href={{ query: { fail: 1 } }}>
      <a>Fail</a>
    </Link>
    {query.fail ? <span>{window.foo.click()}</span> : null}
  </div>
)

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

export default Failing

Reproduce:

  1. Visit deployed minimal example
  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, deployed here

@hanayashiki
Copy link

this looks like a duplicate, now resolved in preact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants