question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lifecycle methods in one component do not get called if an error occurs (and is caught) in an unrelated component.

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mkellyclarecommented, Dec 21, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found