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.

Breaking change in v7 - componentDidUpdate order

See original GitHub issue

We are running into some difficulty updating to v7 due to what seems like a breaking change.

Context: We’re rendering react inside a larger non-react webapp, where when user does some action, some hidden forms get rendered and the form submit.

We detect if it’s time to submit by using componentDidUpdate method on a parent component - relying that child forms have re-rendered by the time componentDidUpdate has been called.

With v7 this seems to be broken - componentDidUpdate for parent is called before child render.

Repro: https://codesandbox.io/embed/eloquent-bas-b12b6

V7 order: image

V6 order: image

This seems like a bug to us as official docs state

componentDidUpdate() is invoked immediately after updating occurs. This method is not called for the initial render. Use this as an opportunity to operate on the DOM when the component has been updated. This is also a good place to do network requests as long as you compare the current props to previous props (e.g. a network request may not be necessary if the props have not changed).

Is the order in v7 intentional?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
macobocommented, Oct 21, 2019

I guess we have no other choice but to try remove our dependency on this behavior going forward, though I’m really surprised by this. Thanks for the help regardless!

0reactions
markeriksoncommented, Nov 8, 2019

@ckedar : no, that’s not correct, and I don’t know why you’re saying that.

connect has always behaved as a PureComponent equivalent, but with a stronger net guarantee: if the combination of const mergedProps = {...ownProps, ...stateProps, ...dispatchProps} hasn’t changed, then your own component won’t render.

The React.memo() usage in v7 is a key part of that implementation, and is necessary for acceptable performance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setState() inside of componentDidUpdate() - Stack Overflow
You can use setState inside componentDidUpdate . The problem is that somehow you are creating an infinite loop because there's no break condition....
Read more >
React lifecycle methods: An approachable tutorial with examples
Learn all about React lifecycle methods for mounting, updating, unmounting, and error handling, including new methods as of React 17.
Read more >
Using the Effect Hook - React
Hooks let us split the code based on what it is doing rather than a lifecycle method name. React will apply every effect...
Read more >
Change Log · Enzyme - GitHub Pages
shallow / mount : make tests and method ordering more consistent (commit); RSTTraversal: remove ... Enzyme has several breaking changes from v2 to...
Read more >
How to use componentDidUpdate in React - DEV Community ...
componentDidUpdate () is called after componentDidMount() and can be useful to perform some action when the state changes.
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