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.

componentDidUpdate inexplicably not firing after render in a single component

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

componentDidUpdate not firing after render in one lone component. No idea how to recreate in a sandbox.

What is the expected behavior?

componentDidUpdate fires after every render

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React@16.11 & React@16.12 affected in Electron@6


I’m tracking when componentDidUpdate and render are firing with log statements.

The log statements in componentDidUpdate do not fire after render. I have used breakpoints to confirm this isn’t a timing issue.

My code (stripped down) is below. This is the output of the logging. Sometimes I’ll get componentDidUpdate to fire, but inconsistently and it’s never the final thing, a RENDER always shows up in my logs last, never UPDATE.

image

class MyWrapper extends React.PureComponent {
  render() {
  const { buttonDefinitions } = this.props;
    return (
      <InfoProvider
        render={infoProps => {
          return (
            <MyMenu
              {...{ buttonDefinitions, infoProps }}
            />
          );
        }}
      />
    );
  }
}
class MyMenu extends React.Component {
  componentDidUpdate() {
    log.warn('UPDATE');
  }

  render() {
    log.warn('RENDER');
    const { buttonDefinitions } = this.props;
    return (
      <MenuWrapper>
        {buttonDefinitions.map(buttonDef => (
          <MyButton {...buttonDef} />
        ))}
      </MenuWrapper>
    );
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bvaughncommented, Dec 23, 2019

If render is called one or more times, componentDidUpdate should call at least once, right?

Not necessarily true, although if the DOM is being modified then the commit phase has run and it should definitely be called in that case.

The profound weirdness of this issue has me hesitant to dive straight into trying to create a repro since I haven’t the faintest clue why this is the only component out of several hundred that I’m seeing this behavior with.

I’d say this is a necessary next step in order for someone to actually look into the issue 🙂 It’s probably going to be easier for you to start stripping things out of your app than it would be for us to speculate about all of the things that could be inside an app we’ve never seen.

0reactions
bvaughncommented, Dec 29, 2019

Ah, interesting! 😄 Thanks for the follow up. Glad you got it sorted out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - componentDidUpdate is not firing - Stack Overflow
componentWillUpdate() is invoked immediately before rendering when new props or state are being received. Use this as an opportunity to perform preparation ...
Read more >
Post-Render with componentDidUpdate() · react-indepth
When componentDidUpdate() is called, two arguments are passed: prevProps and prevState . This is the inverse of componentWillUpdate() . The passed values are ......
Read more >
How does React componentDidUpdate work - Linguine Code
componentDidUpdate is always the last lifecycle to get called for a React component. componentDidUpdate does not get called after the first initial render() ......
Read more >
[Solved]-componentDidUpdate is not firing-Reactjs
componentWillUpdate() is invoked immediately before rendering when new props or state are being received. Use this as an opportunity to perform preparation ...
Read more >
Using React componentDidUpdate() — React Hooks
The React Component Did Update method gets called after a component has been updated. It is invoked immediately after updating occurs and not...
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