Skip to content

Commit d69b424

Browse files
committed
Cleanup after reviewing PR diff
1 parent c308e47 commit d69b424

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export const createPortalNode = <C extends Component<any>>(): PortalNode<C> => {
5555
}
5656
portalNode.unmount();
5757

58-
// To support SVG and other non-html elements, the portalNode's element needs to created with
59-
// the correct namespace.
58+
// To support SVG and other non-html elements, the portalNode's element needs to be
59+
// created with the correct namespace.
6060
if (!portalNode.element || portalNode.element.tagName !== newParent.tagName) {
6161
if (newParent instanceof SVGElement) {
6262
portalNode.element = document.createElementNS(SVG_NAMESPACE, newParent.tagName);
@@ -157,10 +157,7 @@ export class OutPortal<C extends Component<any>> extends React.PureComponent<Out
157157
this.passPropsThroughPortal();
158158
}
159159

160-
passPropsThroughPortal() {
161-
const propsForTarget = Object.assign({}, this.props, { node: undefined });
162-
this.props.node.setPortalProps(propsForTarget);
163-
160+
maybeTriggerOnReady() {
164161
if (this.props.node.onReady) {
165162
// There's an InPortal which is waiting on this OutPortal:
166163
// rerender it now that the OutPortal and portalNode are ready
@@ -169,6 +166,11 @@ export class OutPortal<C extends Component<any>> extends React.PureComponent<Out
169166
}
170167
}
171168

169+
passPropsThroughPortal() {
170+
const propsForTarget = Object.assign({}, this.props, { node: undefined });
171+
this.props.node.setPortalProps(propsForTarget);
172+
}
173+
172174
componentDidMount() {
173175
const node = this.props.node as PortalNode<C>;
174176
this.currentPortalNode = node;
@@ -177,6 +179,7 @@ export class OutPortal<C extends Component<any>> extends React.PureComponent<Out
177179
const parent = placeholder.parentNode!;
178180
node.mount(parent, placeholder);
179181
this.passPropsThroughPortal();
182+
this.maybeTriggerOnReady();
180183
}
181184

182185
componentDidUpdate() {
@@ -194,6 +197,7 @@ export class OutPortal<C extends Component<any>> extends React.PureComponent<Out
194197
const parent = placeholder.parentNode!;
195198
node.mount(parent, placeholder);
196199
this.passPropsThroughPortal();
200+
this.maybeTriggerOnReady();
197201
}
198202

199203
componentWillUnmount() {

stories/index.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ storiesOf('Portals', module)
166166
let portalNode = isPortalSwitched ? portalNode2 : portalNode1;
167167

168168
return <div>
169-
<portals.InPortal node={portalNode}>
169+
<portals.InPortal node={portalNode1}>
170170
<Counter />
171171
</portals.InPortal>
172172
<portals.InPortal node={portalNode2}>

0 commit comments

Comments
 (0)