Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Failed to unmount DOM node after changes #301

Closed
smbape opened this issue Feb 19, 2017 · 1 comment
Closed

Failed to unmount DOM node after changes #301

smbape opened this issue Feb 19, 2017 · 1 comment
Labels
Milestone

Comments

@smbape
Copy link

smbape commented Feb 19, 2017

Hello,

I replace react with preact-compat and I found an issue while unmounting components

jsfiddle

  it("should unmount DOM node after changes", (done) => {
    var SwapComponent = React.createClass({
      getInitialState() {
        return { activated: true };
      },

      swap(evt) {
        evt.preventDefault();
        this.setState({
          activated: !this.state.activated
        });
      },

      render() {
        if (this.state.activated) {
          return <a onClick={ this.swap }>anchor</a>;
        }

        return <b onClick={ this.swap }>bold</b>;
      }
    });

    var container = document.createElement("div");
    document.body.appendChild(container);

    var instance = ReactDOM.render(<SwapComponent />, container);
    var el = ReactDOM.findDOMNode(instance);

    setTimeout(function() {
      trigger(el, "click");
      el = null;
      setTimeout(function() {
        ReactDOM.unmountComponentAtNode(container);
        expect(container.innerHTML).toBe("");
        container = null;
        done();
      }, 2);
    }, 2);
  });

I also found others issues not opened at jsfiddle

@developit
Copy link
Member

Ah - great catch! preact-compat keeps a reference to the DOM element, but when that element changes it's got the wrong reference. It should retain the component instead.

@developit developit added this to the 3.14.0 milestone Feb 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants