@alicloud/alfa-react 1.5.2 → 1.5.4

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.
@@ -48,6 +48,21 @@ var stripBasename = function stripBasename(path, basename) {
48
48
  return _path.replace(new RegExp("^".concat(_basename.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1')), 'ig'), '');
49
49
  };
50
50
 
51
+ /**
52
+ * fix Error (we do not know why):
53
+ * Failed to read the 'state' property from 'History':
54
+ * May not use a History object associated with a Document that is not fully active
55
+ * @returns any
56
+ */
57
+ var getHistoryState = function getHistoryState() {
58
+ try {
59
+ var _window;
60
+ return (_window = window) === null || _window === void 0 ? void 0 : _window.history.state;
61
+ } catch (e) {
62
+ return null;
63
+ }
64
+ };
65
+
51
66
  /**
52
67
  * container for microApp mount
53
68
  * @param loader alfa-core loader
@@ -55,7 +70,6 @@ var stripBasename = function stripBasename(path, basename) {
55
70
  */
56
71
  export default function createApplication(loader) {
57
72
  return function Application(props) {
58
- var _window$history;
59
73
  var name = props.name,
60
74
  version = props.version,
61
75
  manifest = props.manifest,
@@ -103,7 +117,7 @@ export default function createApplication(loader) {
103
117
  // if (customProps.__innerStamp) console.warn('Please do not use __innerStamp which used in internal.');
104
118
  // 更新标记,保证每次更新都会更新
105
119
  customProps.__innerStamp = (+new Date()).toString(36);
106
- customProps.__historyState = (_window$history = window.history) === null || _window$history === void 0 ? void 0 : _window$history.state;
120
+ customProps.__historyState = getHistoryState();
107
121
  if (customProps.path) customProps.path = addLeftSlash(customProps.path);
108
122
 
109
123
  // 受控模式锁定一些参数
@@ -175,7 +189,7 @@ export default function createApplication(loader) {
175
189
  var dispatchFramePopstate = function dispatchFramePopstate() {
176
190
  var _App, _App$context$baseFram, _App$context$baseFram2;
177
191
  var popstateEvent = new Event('popstate');
178
- popstateEvent.state = history.state;
192
+ popstateEvent.state = getHistoryState() || {};
179
193
  (_App = App) === null || _App === void 0 ? void 0 : (_App$context$baseFram = _App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : (_App$context$baseFram2 = _App$context$baseFram.contentWindow) === null || _App$context$baseFram2 === void 0 ? void 0 : _App$context$baseFram2.dispatchEvent(popstateEvent);
180
194
  };
181
195
 
@@ -194,7 +208,7 @@ export default function createApplication(loader) {
194
208
  // 如果主子应用路径不同,主动通知子应用 popstate 事件
195
209
  if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
196
210
  if (originalReplaceState) {
197
- originalReplaceState(history.state, '', stripBasename(peelPath(window.location), $basename.current));
211
+ originalReplaceState(getHistoryState(), '', stripBasename(peelPath(window.location), $basename.current));
198
212
  dispatchFramePopstate();
199
213
  }
200
214
  }
@@ -257,7 +271,7 @@ export default function createApplication(loader) {
257
271
  originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState;
258
272
  originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
259
273
  // update context history according to path
260
- if (path) originalReplaceState(history.state, '', path.replace(/\/+/g, '/'));
274
+ if (path) originalReplaceState(getHistoryState(), '', path.replace(/\/+/g, '/'));
261
275
  if (frameWindow) {
262
276
  frameWindow.history.pushState = function (data, unused, _url) {
263
277
  if ($syncHistory.current) {
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.5.2';
1
+ export var version = '1.5.4';
@@ -58,6 +58,21 @@ var stripBasename = function stripBasename(path, basename) {
58
58
  return _path.replace(new RegExp("^".concat(_basename.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1')), 'ig'), '');
59
59
  };
60
60
 
61
+ /**
62
+ * fix Error (we do not know why):
63
+ * Failed to read the 'state' property from 'History':
64
+ * May not use a History object associated with a Document that is not fully active
65
+ * @returns any
66
+ */
67
+ var getHistoryState = function getHistoryState() {
68
+ try {
69
+ var _window;
70
+ return (_window = window) === null || _window === void 0 ? void 0 : _window.history.state;
71
+ } catch (e) {
72
+ return null;
73
+ }
74
+ };
75
+
61
76
  /**
62
77
  * container for microApp mount
63
78
  * @param loader alfa-core loader
@@ -65,7 +80,6 @@ var stripBasename = function stripBasename(path, basename) {
65
80
  */
66
81
  function createApplication(loader) {
67
82
  return function Application(props) {
68
- var _window$history;
69
83
  var name = props.name,
70
84
  version = props.version,
71
85
  manifest = props.manifest,
@@ -113,7 +127,7 @@ function createApplication(loader) {
113
127
  // if (customProps.__innerStamp) console.warn('Please do not use __innerStamp which used in internal.');
114
128
  // 更新标记,保证每次更新都会更新
115
129
  customProps.__innerStamp = (+new Date()).toString(36);
116
- customProps.__historyState = (_window$history = window.history) === null || _window$history === void 0 ? void 0 : _window$history.state;
130
+ customProps.__historyState = getHistoryState();
117
131
  if (customProps.path) customProps.path = addLeftSlash(customProps.path);
118
132
 
119
133
  // 受控模式锁定一些参数
@@ -185,7 +199,7 @@ function createApplication(loader) {
185
199
  var dispatchFramePopstate = function dispatchFramePopstate() {
186
200
  var _App, _App$context$baseFram, _App$context$baseFram2;
187
201
  var popstateEvent = new Event('popstate');
188
- popstateEvent.state = history.state;
202
+ popstateEvent.state = getHistoryState() || {};
189
203
  (_App = App) === null || _App === void 0 ? void 0 : (_App$context$baseFram = _App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : (_App$context$baseFram2 = _App$context$baseFram.contentWindow) === null || _App$context$baseFram2 === void 0 ? void 0 : _App$context$baseFram2.dispatchEvent(popstateEvent);
190
204
  };
191
205
 
@@ -204,7 +218,7 @@ function createApplication(loader) {
204
218
  // 如果主子应用路径不同,主动通知子应用 popstate 事件
205
219
  if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
206
220
  if (originalReplaceState) {
207
- originalReplaceState(history.state, '', stripBasename(peelPath(window.location), $basename.current));
221
+ originalReplaceState(getHistoryState(), '', stripBasename(peelPath(window.location), $basename.current));
208
222
  dispatchFramePopstate();
209
223
  }
210
224
  }
@@ -267,7 +281,7 @@ function createApplication(loader) {
267
281
  originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState;
268
282
  originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
269
283
  // update context history according to path
270
- if (path) originalReplaceState(history.state, '', path.replace(/\/+/g, '/'));
284
+ if (path) originalReplaceState(getHistoryState(), '', path.replace(/\/+/g, '/'));
271
285
  if (frameWindow) {
272
286
  frameWindow.history.pushState = function (data, unused, _url) {
273
287
  if ($syncHistory.current) {
package/lib/version.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- var version = '1.5.2';
7
+ var version = '1.5.4';
8
8
  exports.version = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-react",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -1 +1 @@
1
- export declare const version = "1.5.2";
1
+ export declare const version = "1.5.4";