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

the child component of ErrorBoundary, wrapped by memo function failed to recover from the last error #3449

Open
1 task done
blinkcat opened this issue Feb 13, 2022 · 2 comments

Comments

@blinkcat
Copy link

blinkcat commented Feb 13, 2022

  • Check if updating to the latest Preact version resolves the issue

Describe the bug
the child componet wrapped by memo function caused an error in the first render, then it's parent component caught the error and solved the error, but this child component disappears in the next render.

To Reproduce

The second Test component disappeared.
https://codesandbox.io/s/charming-curie-to3te?file=/src/index.js

Steps to reproduce the behavior:

Please see the demo above. It's not difficult to reproduce.

Expected behavior

all Test component should be rendered.

@JoviDeCroock
Copy link
Member

This is generally expected when you are using something outside of the closure. When you call memo, much like all the hooks stuff, you are leveraging the variables at that time. You can see that when you pass in causeError as a prop you won't be seeing this issue. https://codesandbox.io/s/headless-cherry-b5z3e?file=/src/index.js:82-582

@blinkcat
Copy link
Author

Hi @JoviDeCroock , thanks for your quick reply.
But, I'm still confused about your explanation. I don't think it's related to closures.

  1. the same demo works as I expected in React. https://stackblitz.com/edit/react-efu258?file=src/App.js
  2. the value of causeError variable is always up-to-date in each render.
  3. when you pass in causeError as a prop, it will only make the default shouldComponentUpdate of memorized component return true, then the diff for this component can continue. it is just a kind of workaround.

Am I right?

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