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

[nextjs] Preact renders 5x when error is thrown in render and cancels rendering route #3233

Open
wilsonpage opened this issue Jul 23, 2021 · 5 comments · May be fixed by #3234
Open

[nextjs] Preact renders 5x when error is thrown in render and cancels rendering route #3233

wilsonpage opened this issue Jul 23, 2021 · 5 comments · May be fixed by #3234

Comments

@wilsonpage
Copy link

Describe the bug
This is a bug related to Preact with Next.JS. If there's a better place to post this please let me know :) When an exception is throw in the render phase of a clientside rendered page the Next.JS pages/_error fails to render.

To Reproduce

Steps to reproduce the behavior:

  1. Visit /
  2. Click link to render /failing
  3. Observe fails to JS console showing 5x render and exceptions

image

Expected behavior

  • Should only invoke pages/failing render once
  • Should then render pages/_error
@developit
Copy link
Member

developit commented Jul 23, 2021

It looks like Next.js is repeatedly re-rendering the route (there are 5 calls to preact.render()), but I think this may be caused by Preact bubbling thrown errors past components with a componentDidCatch() method if that method doesn't set state (which theirs does not):

handled = component._dirty;

Normally, componentDidCatch() needs to invoke setState/forceUpdate in order to mark the component as dirty and "claim" the error - Next seems to just be triggering a full re-render after a Promise tick.

I'd be down to remove this personally, though it's unfortunate to drop conditional error bubbling (kinda a useful feature) to get compat :/

@developit developit linked a pull request Jul 23, 2021 that will close this issue
@developit
Copy link
Member

Can confirm - my PR fixes this, we'll just need to figure out whether the change is something Preact can land without breaking stuff (since it affects how Suspense works). You can try it locally:

yarn add https://pkg.csb.dev/preactjs/preact/commit/90a1d849/preact

@wilsonpage
Copy link
Author

@developit any tips on what I should do here long-term? Is a fix in the works?

@grefrit
Copy link

grefrit commented May 15, 2022

Hello. Any updates on this? This problem still remains with Next 12.1.6, Preact 10.7.2

@JLucasCAmorim
Copy link

Hello guys, any updates? I'm facing the same issue.

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

Successfully merging a pull request may close this issue.

4 participants