react-frame-component 5.2.4 → 5.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/Frame.js +20 -6
  2. package/package.json +1 -1
package/lib/Frame.js CHANGED
@@ -60,7 +60,17 @@ var Frame = exports.Frame = function (_Component) {
60
60
  };
61
61
 
62
62
  _this.handleLoad = function () {
63
- _this.setState({ iframeLoaded: true });
63
+ clearInterval(_this.loadCheck);
64
+ // Bail update as some browsers will trigger on both DOMContentLoaded & onLoad ala firefox
65
+ if (!_this.state.iframeLoaded) {
66
+ _this.setState({ iframeLoaded: true });
67
+ }
68
+ };
69
+
70
+ _this.loadCheck = function () {
71
+ return setInterval(function () {
72
+ _this.handleLoad();
73
+ }, 500);
64
74
  };
65
75
 
66
76
  _this._isMounted = false;
@@ -75,10 +85,9 @@ var Frame = exports.Frame = function (_Component) {
75
85
  this._isMounted = true;
76
86
 
77
87
  var doc = this.getDoc();
78
- if (doc && doc.readyState === 'complete') {
79
- this.forceUpdate();
80
- } else {
81
- this.nodeRef.current.addEventListener('load', this.handleLoad);
88
+
89
+ if (doc) {
90
+ this.nodeRef.current.contentWindow.addEventListener('DOMContentLoaded', this.handleLoad);
82
91
  }
83
92
  }
84
93
  }, {
@@ -86,7 +95,7 @@ var Frame = exports.Frame = function (_Component) {
86
95
  value: function componentWillUnmount() {
87
96
  this._isMounted = false;
88
97
 
89
- this.nodeRef.current.removeEventListener('load', this.handleLoad);
98
+ this.nodeRef.current.removeEventListener('DOMContentLoaded', this.handleLoad);
90
99
  }
91
100
  }, {
92
101
  key: 'getDoc',
@@ -102,6 +111,10 @@ var Frame = exports.Frame = function (_Component) {
102
111
  }
103
112
  return doc.body.children[0];
104
113
  }
114
+
115
+ // In certain situations on a cold cache DOMContentLoaded never gets called
116
+ // fallback to an interval to check if that's the case
117
+
105
118
  }, {
106
119
  key: 'renderFrameContents',
107
120
  value: function renderFrameContents() {
@@ -153,6 +166,7 @@ var Frame = exports.Frame = function (_Component) {
153
166
  delete props.contentDidMount;
154
167
  delete props.contentDidUpdate;
155
168
  delete props.forwardedRef;
169
+
156
170
  return _react2.default.createElement(
157
171
  'iframe',
158
172
  _extends({}, props, { ref: this.setRef, onLoad: this.handleLoad }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-frame-component",
3
- "version": "5.2.4",
3
+ "version": "5.2.6",
4
4
  "description": "React component to wrap your application or component in an iFrame for encapsulation purposes",
5
5
  "main": "lib/index.js",
6
6
  "files": [