Lifecycle methods in one component do not get called if an error occurs (and is caught) in an unrelated component.
See original GitHub issueI have two components that are rendered into two different dom nodes with two separate render calls.
If an Error occurs in the render method of the first component (and is caught), the second component will still render, but it’s componentDidMount lifecycle method will never be called. If the broken component is rendered to the dom after the good component, there is no problem.
I created a minimal example here to reproduce the issue.
Just clone the repo and run yarn start
to start up the dev server.
You will see that the componentDidMount method of the good component is not called.
If you change the order of the rendering in src/index.js it renders correctly.
Edit - added a jsfiddle as well - https://jsfiddle.net/6dhpkxav/3/
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Lifecycle methods in one component do not get called if an ...
Lifecycle methods in one component do not get called if an error occurs (and is caught) in an unrelated component. #958.
Read more >Lifecycle - Lit.dev
Requests an asynchronous update using the requestUpdate() method, so when a Lit component gets upgraded, it performs an update immediately.
Read more >React.Component
A class component becomes an error boundary if it defines either (or both) of the lifecycle methods static getDerivedStateFromError() or componentDidCatch() .
Read more >React Lifecycles | by Byron Skoutaris | Medium
The first thing that gets called is the component constructor, if your component is a class component. This does not apply to functional...
Read more >Lifecycle Methods in React.js - Topcoder
React comes with many lifecycle methods. Each of them has their own purpose and acts during different phases of a component's lifetime, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dfleury see https://github.com/developit/preact/pull/1018
Thanks for the update and the suggestion. In our particular case we are rendering multiple widgets on to a page and each one is wrapped by a common component, so I can work around this issue by handling it there. We also don’t have too many state changes so I think I would prefer the component fail fast and hard, it might lead to some tricky debugging if we added logic to fall back to the last good render. For our case at least. Thanks for all your work on preact, it’s a great project.