Skip to content

Commit 28584e8

Browse files
committed
Fallback to setInterval if DOMContentLoaded fails
1 parent 41c94d3 commit 28584e8

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/Frame.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export class Frame extends Component {
5656
componentWillUnmount() {
5757
this._isMounted = false;
5858

59-
this.nodeRef.current.removeEventListener('load', this.handleLoad);
59+
this.nodeRef.current.removeEventListener(
60+
'DOMContentLoaded',
61+
this.handleLoad
62+
);
6063
}
6164

6265
getDoc() {
@@ -83,12 +86,19 @@ export class Frame extends Component {
8386
};
8487

8588
handleLoad = () => {
89+
clearInterval(this.loadCheck);
8690
// Bail update as some browsers will trigger on both DOMContentLoaded & onLoad ala firefox
8791
if (!this.state.iframeLoaded) {
8892
this.setState({ iframeLoaded: true });
8993
}
9094
};
9195

96+
// In certain situations on a cold cache DOMContentLoaded never gets called
97+
// fallback to an interval to check if that's the case
98+
loadCheck = setInterval(function loadCheckCallback() {
99+
this.handleLoad();
100+
}, 500);
101+
92102
renderFrameContents() {
93103
if (!this._isMounted) {
94104
return null;
@@ -135,6 +145,7 @@ export class Frame extends Component {
135145
delete props.contentDidMount;
136146
delete props.contentDidUpdate;
137147
delete props.forwardedRef;
148+
138149
return (
139150
<iframe {...props} ref={this.setRef} onLoad={this.handleLoad}>
140151
{this.state.iframeLoaded && this.renderFrameContents()}

webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@ module.exports = {
2424
loaders: [
2525
{ test: /\.js(x|)/, loaders: ['babel-loader'], exclude: /node_modules/ }
2626
]
27+
},
28+
devServer: {
29+
headers: {
30+
'Cache-Control': 'max-age=10'
31+
}
2732
}
2833
};

0 commit comments

Comments
 (0)