preact
preact copied to clipboard
the child component of ErrorBoundary, wrapped by memo function failed to recover from the last error
- [x] 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.
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
Hi @JoviDeCroock , thanks for your quick reply. But, I'm still confused about your explanation. I don't think it's related to closures.
- the same demo works as I expected in React. https://stackblitz.com/edit/react-efu258?file=src/App.js
- the value of
causeErrorvariable is always up-to-date in each render. - when you pass in causeError as a prop, it will only make the default
shouldComponentUpdateof memorized component returntrue, then the diff for this component can continue. it is just a kind of workaround.
Am I right?