tajo/react-portal

ReactPortal with React15.x not removing child

shahankit opened this issue · 3 comments

I'm using react-portal with react 15. As per the doc I followed this to toggle contents of portal but with custom node:

{isOpen && <Portal node={this.customNode}>Sometimes portaled?</Portal>}

Because of this when isOpen is false, the portal node is not removed from dom. This issue is because of this condition in LegacyPortal.js. Is there any specific reason that passing a custom node requires to manage toggling content of portal manually. I checked the default reactDom.createPortal does not require so, because running the same code in React 16 works.

tajo commented

Oh, I guess we should do this for Legacy portal.

componentWillUnmount() {
  ReactDOM.unmountComponentAtNode(this.props.node || this.defaultNode);
  if (this.defaultNode) {
    document.body.removeChild(this.defaultNode);
  }
  this.defaultNode = null;
  this.portal = null;
}

Since we want to unmount the child it but preserve the original custom node.

tajo commented

@shahankit It that makes sense, a PR with test would be very appreciated!

Hi @tajo I've added a pull request here: #199