Skip to content

Commit 85b924e

Browse files
committed
handle iframe load event separately
1 parent 761fa5c commit 85b924e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Frame.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ export class Frame extends Component {
5959
this.nodeRef.current.removeEventListener('load', this.handleLoad);
6060
}
6161

62+
onIframeLoad = () => {
63+
this.handleLoad();
64+
if (this.props.onLoad) {
65+
this.props.onLoad();
66+
}
67+
};
68+
6269
getDoc() {
6370
return this.nodeRef.current ? this.nodeRef.current.contentDocument : null; // eslint-disable-line
6471
}
@@ -84,9 +91,6 @@ export class Frame extends Component {
8491

8592
handleLoad = () => {
8693
this.setState({ iframeLoaded: true });
87-
if (this.props.onLoad) {
88-
this.props.onLoad();
89-
}
9094
};
9195

9296
renderFrameContents() {
@@ -136,7 +140,7 @@ export class Frame extends Component {
136140
delete props.contentDidUpdate;
137141
delete props.forwardedRef;
138142
return (
139-
<iframe {...props} ref={this.setRef} onLoad={this.handleLoad}>
143+
<iframe {...props} ref={this.setRef} onLoad={this.onIframeLoad}>
140144
{this.state.iframeLoaded && this.renderFrameContents()}
141145
</iframe>
142146
);

0 commit comments

Comments
 (0)