Skip to content

Commit 90820be

Browse files
committed
fix(Portals): Portals render correctly even if the source does not exist
when the destination is rendered [fixes #138224093]
1 parent e63c3dd commit 90820be

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

library/spec/pivotal-ui-react/portals/portals_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,18 @@ describe('Portals', function() {
191191
expect(orangeWheatley).toContainText('Stop panicking!');
192192
});
193193
});
194+
195+
describe('when the source is rendered significantly after the destination', () => {
196+
it('renders the source portal into the destination portal', () => {
197+
ReactDOM.render((<div><div className="orange"><PortalDestination name="chell"/></div></div>), root);
198+
expect('.orange').not.toHaveText('Potato');
199+
ReactDOM.render(<div><div className="orange"><PortalDestination name="chell"/></div><div className="blue">
200+
<PortalSource name="chell">
201+
<Potato/>
202+
</PortalSource>
203+
</div></div>, root);
204+
expect('.blue').not.toHaveText('Potato');
205+
expect('.orange').toHaveText('Potato');
206+
});
207+
});
194208
});

library/src/pivotal-ui-react/portals/portals.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const reset = () => {
2020
export class PortalSource extends React.PureComponent {
2121
static propTypes = {
2222
name: PropTypes.string.isRequired
23-
}
23+
};
2424

2525
constructor(props, context) {
2626
super(props, context);
@@ -29,6 +29,7 @@ export class PortalSource extends React.PureComponent {
2929

3030
componentWillMount() {
3131
emitter.on('destination', this.setDestination);
32+
this.setDestination();
3233
this.componentDidUpdate();
3334
}
3435

@@ -49,7 +50,7 @@ export class PortalSource extends React.PureComponent {
4950
const {destination} = this.state;
5051
const destinationPortal = destinationPortals[this.props.name];
5152
if (destination && destination.portal === destinationPortal) return;
52-
this.setState({destination: destinationPortal && {portal: destinationPortal, root: createRoot(destinationPortal)}});
53+
this.setState({destination: destinationPortal && {portal: destinationPortal, root: createRoot(destinationPortal)}}, this.componentDidUpdate);
5354
}
5455

5556
render() {

0 commit comments

Comments
 (0)