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.

IE unable to render elements after state has changed

See original GitHub issue

I found some issues using react-popout on IE. The main issue can be examplified by the following piece of simple code:

    import React from 'react';
    import ReactDOM from 'react-dom';
    import domready from 'domready';
    import Popout from '../lib/react-popout.jsx';

    class AnotherCoolComponent extends React.Component {
      render() {
        return (
         <p>{this.props.sentence}</p>
        );
      }
    }

    class Example extends React.Component {
      constructor(props) {
        super(props);
        this.popout = this.popout.bind(this);
        this.popoutClosed = this.popoutClosed.bind(this);
        this.popoutContentClicked = this.popoutContentClicked.bind(this);
        this.showSomething = this.showSomething.bind(this);
        this.state = {
          isPoppedOut: false,
          showSomething: false,
        };
      }

      popout() {
        this.setState({isPoppedOut: true});
      }

      popoutClosed() {
        this.setState({isPoppedOut: false});
      }

      showSomething() {
        this.setState({
          showSomething: !this.state.showSomething
        });
      }

      popoutContentClicked() {
        this.popoutClosed();
      }

      render() {
        if (this.state.isPoppedOut) {
          return (
            <Popout title='Test' onClosing={this.popoutClosed}>
              <div>
                <button onClick={this.popoutContentClicked}>Close</button>
                <button onClick={this.showSomething}>Click here to show something</button>
                {this.state.showSomething && <AnotherCoolComponent sentence="testing" />}
              </div>
            </Popout>
          );
        } else {
          return (
            <a onClick={this.popout}>(pop window out)</a>
          );
        }
      }
    }

    domready(() => {
      var container = document.createElement('div');
      document.body.appendChild(container);
      ReactDOM.render(<Example />, container);
    });

When a change on the state of the component inside the popout causes a new component to be rendered, React for some reason, is unable to render it and throws errors:

It's not possible to get property "firstChild" of undefined reference or null

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lucaspincommented, Apr 1, 2016

This issue is from React, and was fixed on version 15.0 (https://github.com/facebook/react/issues/5755)

0reactions
bigassdragoncommented, Apr 1, 2016

I struggled with this for a very long time.

To my understanding it seems like IE is expecting the DOM to have the same tree on a child component. So if you have a div with some data in it, it is going to expect the same tree to exist but you can empty that out if you want.

I have not exactly found a great way to fix it, but my first pass at it was making the update function unmountComponentAtNode only for IE. Doing this caused a flicker to happen because of the constant unmounting.

I have yet to find a better solution in the mean time. If anyone has any ideas that could help me make this better I can do so and do a pull request if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is useState not triggering re-render? - Stack Overflow
To anyone confused as to why this happens, is because setSomething() only re renders the component if and only if the previous and...
Read more >
Internet Explorer (IE) mode troubleshooting and FAQ
Troubleshooting guide and FAQ for Microsoft Edge Internet Explorer mode.
Read more >
React re-renders guide: everything, all at once - Developer way
There are four reasons why a component would re-render itself: state changes, parent (or children) re-renders, context changes, and hooks ...
Read more >
When does React render your component? - Zhenghao
Your component has been rendered before i.e. it already mounted; No props (referentially) changed; No any context value consumed by your ...
Read more >
How to solve too many re-renders error in ReactJS?
After mounting a React component, it will listen to any React props or state that has changed. It will, by default, re-render the...
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