Skip to content

Commit 6ec7f89

Browse files
committed
reset InPortal nodeProps on OutPortal node update or unmount
1 parent 3426281 commit 6ec7f89

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,11 @@ class OutPortal<C extends Component<any>> extends React.PureComponent<OutPortalP
205205
this.passPropsThroughPortal();
206206
}
207207

208-
componentDidUpdate() {
208+
componentDidUpdate(prevProps: OutPortalProps<C>) {
209209
// We re-mount on update, just in case we were unmounted (e.g. by
210210
// a second OutPortal, which has now been removed)
211211
const node = this.props.node as AnyPortalNode<C>;
212+
const prevNode = prevProps.node
212213

213214
// If we're switching portal nodes, we need to clean up the current one first.
214215
if (this.currentPortalNode && node !== this.currentPortalNode) {
@@ -220,11 +221,15 @@ class OutPortal<C extends Component<any>> extends React.PureComponent<OutPortalP
220221
const parent = placeholder.parentNode!;
221222
node.mount(parent, placeholder);
222223
this.passPropsThroughPortal();
224+
if (prevNode !== node) {
225+
prevNode.setPortalProps({} as ComponentProps<C>);
226+
}
223227
}
224228

225229
componentWillUnmount() {
226230
const node = this.props.node as AnyPortalNode<C>;
227231
node.unmount(this.placeholderNode.current!);
232+
node.setPortalProps({} as ComponentProps<C>);
228233
}
229234

230235
render() {

0 commit comments

Comments
 (0)