From 960dd92cf1bc8390302787fbf2d28d67f0595a6e Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 23 Jun 2020 10:14:24 +0100 Subject: [PATCH] Fix React warning while unmounting slots (#23365) --- packages/components/src/slot-fill/slot.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/components/src/slot-fill/slot.js b/packages/components/src/slot-fill/slot.js index 87ac857fda5816..1376d40f2efbd8 100644 --- a/packages/components/src/slot-fill/slot.js +++ b/packages/components/src/slot-fill/slot.js @@ -22,6 +22,7 @@ class SlotComponent extends Component { constructor() { super( ...arguments ); + this.isUnmounted = false; this.bindNode = this.bindNode.bind( this ); } @@ -33,7 +34,7 @@ class SlotComponent extends Component { componentWillUnmount() { const { unregisterSlot } = this.props; - + this.isUnmounted = true; unregisterSlot( this.props.name, this ); } @@ -50,6 +51,13 @@ class SlotComponent extends Component { this.node = node; } + forceUpdate() { + if ( this.isUnmounted ) { + return; + } + super.forceUpdate(); + } + render() { const { children, name, fillProps = {}, getFills } = this.props;