-
Notifications
You must be signed in to change notification settings - Fork 813
Hot reload removing portal node on storybook. #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Probably related to facebook/react#14811 |
Hi @bertho-zero, not sure if it is a good idea. Maybe this can hide bugs when removing the portal node. Perhaps, we can try to make a dead branch elimination: if (process.env.NODE_ENV === 'development') {
(parent && parent.removeChild(this.node)) ||
console.warn("Portal node has gone.");
} else {
parent.removeChild(this.node);
} What do you think? (Just trying to be safe.) |
Also, if you can provide more information about the setup, it might help...and thanks for reporting this issue. |
This problem is not related to hot reload, I have the same problem in production as soon as the component is unmount. I have a component that does not use class GnaGna extends Component {
schedulerRef = React.createRef();
getModalParent = () => this.schedulerRef.current;
render() {
return (
<>
<div ref={this.schedulerRef} />
<ReactModal
parentSelector={this.getModalParent}
/>
</>
);
}
} |
If I put the modal before I have an error with .appendChild, if I put it after the parent disappears before calling .removeChild. |
I found a workaround: class GnaGna extends Component {
schedulerRef = React.createRef();
modalRef = React.createRef();
componentWillUnmount() {
this.modalRef.current.node = null;
}
getModalParent = () => this.schedulerRef.current;
render() {
return (
<>
<div ref={this.schedulerRef} />
<ReactModal
ref={this.modalRef}
parentSelector={this.getModalParent}
/>
</>
);
}
} |
This patch was superseded by #778. |
In a storybook the hot reload removes the parent before the .removeChild, which makes this mistake once in two:
Can not read property 'removeChild' of null