@alicloud/alfa-react 1.4.31 → 1.4.33-alpha.0

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.
@@ -34,6 +34,17 @@ var addBasename = function addBasename(path, basename) {
34
34
  return resolvePath(basename, path);
35
35
  };
36
36
 
37
+ var addLeftSlash = function addLeftSlash(path) {
38
+ return path.charAt(0) === '/' ? path : "/".concat(path);
39
+ };
40
+ /**
41
+ * 从 path 移除 basename 部分
42
+ * @param path
43
+ * @param basename
44
+ * @returns string
45
+ */
46
+
47
+
37
48
  var stripBasename = function stripBasename(path, basename) {
38
49
  if (!basename) return path;
39
50
 
@@ -92,7 +103,8 @@ export default function createApplication(loader) {
92
103
  var $basename = useRef(basename);
93
104
  var tagName = normalizeName(props.name);
94
105
  $syncHistory.current = syncHistory;
95
- $basename.current = basename; // 受控模式锁定一些参数
106
+ $basename.current = basename;
107
+ if (customProps.path) customProps.path = addLeftSlash(customProps.path); // 受控模式锁定一些参数
96
108
 
97
109
  if ($syncHistory.current) {
98
110
  // 禁止子应用和 consoleBase 通信
@@ -166,24 +178,25 @@ export default function createApplication(loader) {
166
178
  var popstateEvent = new Event('popstate');
167
179
  popstateEvent.state = 'mock';
168
180
  (_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);
169
- }; // 受控模式下,返回不会触发子应用内的路由更新
170
-
181
+ };
171
182
 
172
183
  var updateAppHistory = function updateAppHistory() {
173
184
  if (App) {
174
- // 如果子应用路径不同,主动通知子应用 popstate 事件
175
- var nextPath = peelPath(App.context.location);
185
+ var nextPath = peelPath(App.context.location); // 路由同步只应该在相同 basename 下生效
186
+
187
+ if (!peelPath(window.location).startsWith($basename.current || '')) return; // 如果主子应用路径不同,主动通知子应用 popstate 事件
176
188
 
177
189
  if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
178
- var popstateEvent = new Event('popstate');
179
- popstateEvent.state = 'mock';
180
- if (originalReplaceState) originalReplaceState(null, '', stripBasename(peelPath(window.location), $basename.current));
181
- dispatchFramePopstate();
190
+ if (originalReplaceState) {
191
+ originalReplaceState(null, '', stripBasename(peelPath(window.location), $basename.current));
192
+ dispatchFramePopstate();
193
+ }
182
194
  }
183
195
  }
184
- };
196
+ }; // 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
197
+
185
198
 
186
- window.addEventListener('popstate', updateAppHistory);
199
+ if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
187
200
 
188
201
  _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
189
202
  var _app$context$updateBo, _app$context, _app$context$baseFram;
@@ -309,7 +322,7 @@ export default function createApplication(loader) {
309
322
  var _App$context$baseFram3, _App$context$baseFram4;
310
323
 
311
324
  isUnmounted = true;
312
- window.removeEventListener('popstate', updateAppHistory);
325
+ if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
313
326
  if (!App) return;
314
327
  var frameHistory = (_App$context$baseFram3 = App.context.baseFrame) === null || _App$context$baseFram3 === void 0 ? void 0 : (_App$context$baseFram4 = _App$context$baseFram3.contentWindow) === null || _App$context$baseFram4 === void 0 ? void 0 : _App$context$baseFram4.history;
315
328
 
@@ -319,7 +332,8 @@ export default function createApplication(loader) {
319
332
  if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
320
333
  }
321
334
 
322
- App.unmount();
335
+ App.unmount(); // TODO: 在沙箱中嵌套时,unmount 必须销毁沙箱实例,避免在其它微应用中复用该沙箱,导致环境变量污染
336
+ // if (isOsContext()) App.destroy();
323
337
  };
324
338
  }, [memoOptions]);
325
339
 
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.4.31';
1
+ export var version = '1.4.33-alpha.0';
@@ -56,6 +56,17 @@ var addBasename = function addBasename(path, basename) {
56
56
  return resolvePath(basename, path);
57
57
  };
58
58
 
59
+ var addLeftSlash = function addLeftSlash(path) {
60
+ return path.charAt(0) === '/' ? path : "/".concat(path);
61
+ };
62
+ /**
63
+ * 从 path 移除 basename 部分
64
+ * @param path
65
+ * @param basename
66
+ * @returns string
67
+ */
68
+
69
+
59
70
  var stripBasename = function stripBasename(path, basename) {
60
71
  if (!basename) return path;
61
72
 
@@ -114,7 +125,8 @@ function createApplication(loader) {
114
125
  var $basename = (0, _react.useRef)(basename);
115
126
  var tagName = (0, _utils.normalizeName)(props.name);
116
127
  $syncHistory.current = syncHistory;
117
- $basename.current = basename; // 受控模式锁定一些参数
128
+ $basename.current = basename;
129
+ if (customProps.path) customProps.path = addLeftSlash(customProps.path); // 受控模式锁定一些参数
118
130
 
119
131
  if ($syncHistory.current) {
120
132
  // 禁止子应用和 consoleBase 通信
@@ -188,24 +200,25 @@ function createApplication(loader) {
188
200
  var popstateEvent = new Event('popstate');
189
201
  popstateEvent.state = 'mock';
190
202
  (_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);
191
- }; // 受控模式下,返回不会触发子应用内的路由更新
192
-
203
+ };
193
204
 
194
205
  var updateAppHistory = function updateAppHistory() {
195
206
  if (App) {
196
- // 如果子应用路径不同,主动通知子应用 popstate 事件
197
- var nextPath = peelPath(App.context.location);
207
+ var nextPath = peelPath(App.context.location); // 路由同步只应该在相同 basename 下生效
208
+
209
+ if (!peelPath(window.location).startsWith($basename.current || '')) return; // 如果主子应用路径不同,主动通知子应用 popstate 事件
198
210
 
199
211
  if (nextPath !== stripBasename(peelPath(window.location), $basename.current)) {
200
- var popstateEvent = new Event('popstate');
201
- popstateEvent.state = 'mock';
202
- if (originalReplaceState) originalReplaceState(null, '', stripBasename(peelPath(window.location), $basename.current));
203
- dispatchFramePopstate();
212
+ if (originalReplaceState) {
213
+ originalReplaceState(null, '', stripBasename(peelPath(window.location), $basename.current));
214
+ dispatchFramePopstate();
215
+ }
204
216
  }
205
217
  }
206
- };
218
+ }; // 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
219
+
207
220
 
208
- window.addEventListener('popstate', updateAppHistory);
221
+ if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
209
222
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
210
223
  var _app$context$updateBo, _app$context, _app$context$baseFram;
211
224
 
@@ -329,7 +342,7 @@ function createApplication(loader) {
329
342
  var _App$context$baseFram3, _App$context$baseFram4;
330
343
 
331
344
  isUnmounted = true;
332
- window.removeEventListener('popstate', updateAppHistory);
345
+ if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
333
346
  if (!App) return;
334
347
  var frameHistory = (_App$context$baseFram3 = App.context.baseFrame) === null || _App$context$baseFram3 === void 0 ? void 0 : (_App$context$baseFram4 = _App$context$baseFram3.contentWindow) === null || _App$context$baseFram4 === void 0 ? void 0 : _App$context$baseFram4.history;
335
348
 
@@ -339,7 +352,8 @@ function createApplication(loader) {
339
352
  if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
340
353
  }
341
354
 
342
- App.unmount();
355
+ App.unmount(); // TODO: 在沙箱中嵌套时,unmount 必须销毁沙箱实例,避免在其它微应用中复用该沙箱,导致环境变量污染
356
+ // if (isOsContext()) App.destroy();
343
357
  };
344
358
  }, [memoOptions]);
345
359
 
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.4.31';
7
+ var version = '1.4.33-alpha.0';
8
8
  exports.version = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-react",
3
- "version": "1.4.31",
3
+ "version": "1.4.33-alpha.0",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -2,7 +2,11 @@
2
2
  import { BaseLoader } from '@alicloud/alfa-core';
3
3
  import { AlfaFactoryOption } from './types';
4
4
  interface IProps<C = any> extends AlfaFactoryOption {
5
- customProps: C;
5
+ customProps: C & {
6
+ consoleBase?: any;
7
+ path?: string;
8
+ __injectHistory?: any;
9
+ };
6
10
  syncHistory?: boolean;
7
11
  basename?: string;
8
12
  }
@@ -1 +1 @@
1
- export declare const version = "1.4.31";
1
+ export declare const version = "1.4.33-alpha.0";