@alicloud/alfa-react 1.4.29 → 1.4.30-alpha.1

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.
@@ -32,6 +32,8 @@ function createAlfaApp(option) {
32
32
  });
33
33
 
34
34
  return /*#__PURE__*/React.createElement(ErrorBoundary, props, /*#__PURE__*/React.createElement(Application, _extends({}, passedInOption, {
35
+ puppeteer: props.puppeteer,
36
+ basename: props.basename,
35
37
  sandbox: option.sandbox || props.sandbox,
36
38
  deps: dependencies || {},
37
39
  customProps: customProps
@@ -10,7 +10,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
 
11
11
  import React, { useRef, useEffect, useState, useMemo } from 'react';
12
12
  import Loading from './components/Loading';
13
- import { normalizeName } from './utils';
13
+ import { normalizeName, isOsContext } from './utils';
14
14
  import { version as loaderVersion } from './version';
15
15
 
16
16
  /**
@@ -40,7 +40,10 @@ export default function createApplication(loader) {
40
40
  beforeUpdate = props.beforeUpdate,
41
41
  customSandbox = props.sandbox,
42
42
  locale = props.locale,
43
- dynamicConfig = props.dynamicConfig;
43
+ dynamicConfig = props.dynamicConfig,
44
+ noCache = props.noCache,
45
+ puppeteer = props.puppeteer,
46
+ basename = props.basename;
44
47
 
45
48
  var _useState = useState(null),
46
49
  _useState2 = _slicedToArray(_useState, 2),
@@ -52,7 +55,11 @@ export default function createApplication(loader) {
52
55
  setError = _useState4[1];
53
56
 
54
57
  var appRef = useRef(undefined);
58
+ var $puppeteer = useRef(puppeteer);
59
+ var $basename = useRef(basename);
55
60
  var tagName = normalizeName(props.name);
61
+ $puppeteer.current = puppeteer;
62
+ $basename.current = basename;
56
63
  var sandbox = useMemo(function () {
57
64
  var _UA_Opt, _RISK_INFO, _um;
58
65
 
@@ -98,6 +105,7 @@ export default function createApplication(loader) {
98
105
  afterUnmount: afterUnmount,
99
106
  beforeUpdate: beforeUpdate,
100
107
  locale: locale,
108
+ noCache: noCache,
101
109
  // 用户自定义 manifest 且未传入 dynamicConfig 时,默认值为 false,否则为 true
102
110
  dynamicConfig: typeof dynamicConfig === 'boolean' ? dynamicConfig : !manifest
103
111
  };
@@ -105,11 +113,13 @@ export default function createApplication(loader) {
105
113
  useEffect(function () {
106
114
  var isUnmounted = false;
107
115
  var App;
116
+ var originalPushState;
117
+ var originalReplaceState;
108
118
 
109
119
  _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
110
- var _app$context$updateBo, _app$context;
120
+ var _app$context$updateBo, _app$context, _app$context$baseFram;
111
121
 
112
- var _yield$loader$registe, app, logger;
122
+ var _yield$loader$registe, app, logger, _ref2, path, frameWindow;
113
123
 
114
124
  return _regeneratorRuntime.wrap(function _callee$(_context) {
115
125
  while (1) {
@@ -158,15 +168,38 @@ export default function createApplication(loader) {
158
168
  case 12:
159
169
  // update body in sandbox context
160
170
  (_app$context$updateBo = (_app$context = app.context).updateBody) === null || _app$context$updateBo === void 0 ? void 0 : _app$context$updateBo.call(_app$context, memoOptions.sandbox.disableFakeBody ? document.body : appRef.current);
161
- _context.next = 15;
171
+ _ref2 = memoOptions.props, path = _ref2.path;
172
+ frameWindow = (_app$context$baseFram = app.context.baseFrame) === null || _app$context$baseFram === void 0 ? void 0 : _app$context$baseFram.contentWindow;
173
+
174
+ if (frameWindow) {
175
+ originalPushState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.pushState;
176
+ originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState; // update context history according to path
177
+
178
+ if (path) originalReplaceState(null, '', path);
179
+
180
+ if ($puppeteer.current && frameWindow) {
181
+ frameWindow.history.pushState = function (data, unused, _url) {
182
+ window.history.pushState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
183
+ originalReplaceState(data, unused, _url);
184
+ };
185
+
186
+ frameWindow.history.replaceState = function (data, unused, _url) {
187
+ window.history.replaceState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
188
+ originalReplaceState(data, unused, _url);
189
+ };
190
+ }
191
+ }
192
+
193
+ _context.next = 18;
162
194
  return app.mount(appRef.current, {
163
195
  customProps: customProps
164
196
  });
165
197
 
166
- case 15:
198
+ case 18:
199
+ // just run once
167
200
  setAppInstance(app);
168
201
 
169
- case 16:
202
+ case 19:
170
203
  case "end":
171
204
  return _context.stop();
172
205
  }
@@ -179,8 +212,16 @@ export default function createApplication(loader) {
179
212
  });
180
213
 
181
214
  return function () {
215
+ var _App$context$baseFram;
216
+
182
217
  isUnmounted = true;
183
- App && App.unmount();
218
+ if (!App) return;
219
+ App.unmount();
220
+ var frameWindow = (_App$context$baseFram = App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : _App$context$baseFram.contentWindow;
221
+ if (frameWindow && originalPushState) frameWindow.history.pushState = originalPushState;
222
+ if (frameWindow && originalReplaceState) frameWindow.history.pushState = originalReplaceState; // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
223
+
224
+ if (isOsContext()) App.destroy();
184
225
  };
185
226
  }, [memoOptions]);
186
227
 
@@ -18,7 +18,7 @@ function afterLoadHook(_x) {
18
18
 
19
19
  function _afterLoadHook() {
20
20
  _afterLoadHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appConfig) {
21
- var app, logger, sandbox, dynamicConfig, defaultConsoleConfig, defaultConsoleGlobal, CONFIG_START_TIME, CONFIG_END_TIME, configData, _yield$Promise$all, _yield$Promise$all2, consoleConfig, consoleGlobal, messages, i18nMessages, END_TIME;
21
+ var app, logger, sandbox, dynamicConfig, defaultConsoleConfig, defaultConsoleGlobal, CONFIG_START_TIME, CONFIG_END_TIME, configData, _yield$Promise$all, _yield$Promise$all2, consoleConfig, consoleGlobal, messages, i18nMessages, overrides, END_TIME;
22
22
 
23
23
  return _regeneratorRuntime.wrap(function _callee$(_context) {
24
24
  while (1) {
@@ -71,6 +71,18 @@ function _afterLoadHook() {
71
71
  }
72
72
 
73
73
  case 22:
74
+ overrides = sandbox === null || sandbox === void 0 ? void 0 : sandbox.overrideGlobalVars;
75
+
76
+ if (overrides && app) {
77
+ Object.entries(overrides).forEach(function (_ref) {
78
+ var _ref2 = _slicedToArray(_ref, 2),
79
+ key = _ref2[0],
80
+ value = _ref2[1];
81
+
82
+ app.context.window[key] = value;
83
+ });
84
+ }
85
+
74
86
  END_TIME = Date.now();
75
87
  (logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
76
88
  CONFIG_START_TIME: CONFIG_START_TIME,
@@ -81,7 +93,7 @@ function _afterLoadHook() {
81
93
  (logger === null || logger === void 0 ? void 0 : logger.send) && logger.send();
82
94
  return _context.abrupt("return", appConfig);
83
95
 
84
- case 26:
96
+ case 28:
85
97
  case "end":
86
98
  return _context.stop();
87
99
  }
package/es/utils/index.js CHANGED
@@ -1,3 +1,19 @@
1
+ /**
2
+ * kernel 会为沙箱 context 注入 __IS_CONSOLE_OS_CONTEXT__
3
+ */
1
4
  export var normalizeName = function normalizeName(name) {
2
5
  return name.replace(/@/g, '').replace(/\//g, '-');
6
+ };
7
+ /**
8
+ * 判断是否在沙箱环境中运行
9
+ */
10
+
11
+ export var isOsContext = function isOsContext() {
12
+ try {
13
+ return context.__IS_CONSOLE_OS_CONTEXT__;
14
+ } catch (e) {
15
+ // 历史逻辑问题,window.__IS_CONSOLE_OS_CONTEXT__ 会被污染导致判断异常
16
+ // 降级
17
+ return !!window.__IS_CONSOLE_OS_CONTEXT__;
18
+ }
3
19
  };
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.4.29';
1
+ export var version = '1.4.30-alpha.1';
@@ -49,6 +49,8 @@ function createAlfaApp(option) {
49
49
  });
50
50
 
51
51
  return /*#__PURE__*/_react.default.createElement(_ErrorBoundary.default, props, /*#__PURE__*/_react.default.createElement(Application, (0, _extends2.default)({}, passedInOption, {
52
+ puppeteer: props.puppeteer,
53
+ basename: props.basename,
52
54
  sandbox: option.sandbox || props.sandbox,
53
55
  deps: dependencies || {},
54
56
  customProps: customProps
@@ -62,7 +62,10 @@ function createApplication(loader) {
62
62
  beforeUpdate = props.beforeUpdate,
63
63
  customSandbox = props.sandbox,
64
64
  locale = props.locale,
65
- dynamicConfig = props.dynamicConfig;
65
+ dynamicConfig = props.dynamicConfig,
66
+ noCache = props.noCache,
67
+ puppeteer = props.puppeteer,
68
+ basename = props.basename;
66
69
 
67
70
  var _useState = (0, _react.useState)(null),
68
71
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -74,7 +77,11 @@ function createApplication(loader) {
74
77
  setError = _useState4[1];
75
78
 
76
79
  var appRef = (0, _react.useRef)(undefined);
80
+ var $puppeteer = (0, _react.useRef)(puppeteer);
81
+ var $basename = (0, _react.useRef)(basename);
77
82
  var tagName = (0, _utils.normalizeName)(props.name);
83
+ $puppeteer.current = puppeteer;
84
+ $basename.current = basename;
78
85
  var sandbox = (0, _react.useMemo)(function () {
79
86
  var _UA_Opt, _RISK_INFO, _um;
80
87
 
@@ -120,6 +127,7 @@ function createApplication(loader) {
120
127
  afterUnmount: afterUnmount,
121
128
  beforeUpdate: beforeUpdate,
122
129
  locale: locale,
130
+ noCache: noCache,
123
131
  // 用户自定义 manifest 且未传入 dynamicConfig 时,默认值为 false,否则为 true
124
132
  dynamicConfig: typeof dynamicConfig === 'boolean' ? dynamicConfig : !manifest
125
133
  };
@@ -127,10 +135,12 @@ function createApplication(loader) {
127
135
  (0, _react.useEffect)(function () {
128
136
  var isUnmounted = false;
129
137
  var App;
138
+ var originalPushState;
139
+ var originalReplaceState;
130
140
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
131
- var _app$context$updateBo, _app$context;
141
+ var _app$context$updateBo, _app$context, _app$context$baseFram;
132
142
 
133
- var _yield$loader$registe, app, logger;
143
+ var _yield$loader$registe, app, logger, _ref2, path, frameWindow;
134
144
 
135
145
  return _regenerator.default.wrap(function _callee$(_context) {
136
146
  while (1) {
@@ -179,15 +189,38 @@ function createApplication(loader) {
179
189
  case 12:
180
190
  // update body in sandbox context
181
191
  (_app$context$updateBo = (_app$context = app.context).updateBody) === null || _app$context$updateBo === void 0 ? void 0 : _app$context$updateBo.call(_app$context, memoOptions.sandbox.disableFakeBody ? document.body : appRef.current);
182
- _context.next = 15;
192
+ _ref2 = memoOptions.props, path = _ref2.path;
193
+ frameWindow = (_app$context$baseFram = app.context.baseFrame) === null || _app$context$baseFram === void 0 ? void 0 : _app$context$baseFram.contentWindow;
194
+
195
+ if (frameWindow) {
196
+ originalPushState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.pushState;
197
+ originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState; // update context history according to path
198
+
199
+ if (path) originalReplaceState(null, '', path);
200
+
201
+ if ($puppeteer.current && frameWindow) {
202
+ frameWindow.history.pushState = function (data, unused, _url) {
203
+ window.history.pushState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
204
+ originalReplaceState(data, unused, _url);
205
+ };
206
+
207
+ frameWindow.history.replaceState = function (data, unused, _url) {
208
+ window.history.replaceState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
209
+ originalReplaceState(data, unused, _url);
210
+ };
211
+ }
212
+ }
213
+
214
+ _context.next = 18;
183
215
  return app.mount(appRef.current, {
184
216
  customProps: customProps
185
217
  });
186
218
 
187
- case 15:
219
+ case 18:
220
+ // just run once
188
221
  setAppInstance(app);
189
222
 
190
- case 16:
223
+ case 19:
191
224
  case "end":
192
225
  return _context.stop();
193
226
  }
@@ -199,8 +232,16 @@ function createApplication(loader) {
199
232
  });
200
233
  });
201
234
  return function () {
235
+ var _App$context$baseFram;
236
+
202
237
  isUnmounted = true;
203
- App && App.unmount();
238
+ if (!App) return;
239
+ App.unmount();
240
+ var frameWindow = (_App$context$baseFram = App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : _App$context$baseFram.contentWindow;
241
+ if (frameWindow && originalPushState) frameWindow.history.pushState = originalPushState;
242
+ if (frameWindow && originalReplaceState) frameWindow.history.pushState = originalReplaceState; // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
243
+
244
+ if ((0, _utils.isOsContext)()) App.destroy();
204
245
  };
205
246
  }, [memoOptions]);
206
247
 
@@ -32,7 +32,7 @@ function afterLoadHook(_x) {
32
32
 
33
33
  function _afterLoadHook() {
34
34
  _afterLoadHook = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(appConfig) {
35
- var app, logger, sandbox, dynamicConfig, defaultConsoleConfig, defaultConsoleGlobal, CONFIG_START_TIME, CONFIG_END_TIME, configData, _yield$Promise$all, _yield$Promise$all2, consoleConfig, consoleGlobal, messages, i18nMessages, END_TIME;
35
+ var app, logger, sandbox, dynamicConfig, defaultConsoleConfig, defaultConsoleGlobal, CONFIG_START_TIME, CONFIG_END_TIME, configData, _yield$Promise$all, _yield$Promise$all2, consoleConfig, consoleGlobal, messages, i18nMessages, overrides, END_TIME;
36
36
 
37
37
  return _regenerator.default.wrap(function _callee$(_context) {
38
38
  while (1) {
@@ -85,6 +85,18 @@ function _afterLoadHook() {
85
85
  }
86
86
 
87
87
  case 22:
88
+ overrides = sandbox === null || sandbox === void 0 ? void 0 : sandbox.overrideGlobalVars;
89
+
90
+ if (overrides && app) {
91
+ Object.entries(overrides).forEach(function (_ref) {
92
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
93
+ key = _ref2[0],
94
+ value = _ref2[1];
95
+
96
+ app.context.window[key] = value;
97
+ });
98
+ }
99
+
88
100
  END_TIME = Date.now();
89
101
  (logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
90
102
  CONFIG_START_TIME: CONFIG_START_TIME,
@@ -95,7 +107,7 @@ function _afterLoadHook() {
95
107
  (logger === null || logger === void 0 ? void 0 : logger.send) && logger.send();
96
108
  return _context.abrupt("return", appConfig);
97
109
 
98
- case 26:
110
+ case 28:
99
111
  case "end":
100
112
  return _context.stop();
101
113
  }
@@ -3,10 +3,29 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.normalizeName = void 0;
6
+ exports.normalizeName = exports.isOsContext = void 0;
7
7
 
8
+ /**
9
+ * kernel 会为沙箱 context 注入 __IS_CONSOLE_OS_CONTEXT__
10
+ */
8
11
  var normalizeName = function normalizeName(name) {
9
12
  return name.replace(/@/g, '').replace(/\//g, '-');
10
13
  };
14
+ /**
15
+ * 判断是否在沙箱环境中运行
16
+ */
11
17
 
12
- exports.normalizeName = normalizeName;
18
+
19
+ exports.normalizeName = normalizeName;
20
+
21
+ var isOsContext = function isOsContext() {
22
+ try {
23
+ return context.__IS_CONSOLE_OS_CONTEXT__;
24
+ } catch (e) {
25
+ // 历史逻辑问题,window.__IS_CONSOLE_OS_CONTEXT__ 会被污染导致判断异常
26
+ // 降级
27
+ return !!window.__IS_CONSOLE_OS_CONTEXT__;
28
+ }
29
+ };
30
+
31
+ exports.isOsContext = isOsContext;
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.29';
7
+ var version = '1.4.30-alpha.1';
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.29",
3
+ "version": "1.4.30-alpha.1",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -42,8 +42,8 @@
42
42
  "typescript": "^3.0.3"
43
43
  },
44
44
  "dependencies": {
45
- "@alicloud/alfa-core": "^1.4.25",
46
- "@alicloud/console-os-loader": "^1.4.14-alpha.1",
45
+ "@alicloud/alfa-core": "1.4.30-alpha.0",
46
+ "@alicloud/console-os-loader": "1.4.30-alpha.0",
47
47
  "@alicloud/widget-utils-console": "^0.1.6",
48
48
  "classnames": "^2.2.6",
49
49
  "crypto-js": "^4.1.1"
@@ -51,5 +51,5 @@
51
51
  "peerDependencies": {
52
52
  "react": ">=16.0.0"
53
53
  },
54
- "gitHead": "7ba041c936d2d2738a4675710bbc979b7973ff67"
54
+ "gitHead": "ff9294b1d5e08b14691c8aa2bef098da2857f3df"
55
55
  }
@@ -3,5 +3,7 @@ import { AlfaFactoryOption } from './types';
3
3
  declare function createAlfaApp<P = any>(option: AlfaFactoryOption): (() => null) | React.MemoExoticComponent<(props: P & {
4
4
  history: any;
5
5
  sandbox: {};
6
+ puppeteer?: boolean;
7
+ basename?: string;
6
8
  }) => JSX.Element>;
7
9
  export default createAlfaApp;
@@ -3,6 +3,8 @@ import { BaseLoader } from '@alicloud/alfa-core';
3
3
  import { AlfaFactoryOption } from './types';
4
4
  interface IProps<C = any> extends AlfaFactoryOption {
5
5
  customProps: C;
6
+ puppeteer?: boolean;
7
+ basename?: string;
6
8
  }
7
9
  /**
8
10
  * container for microApp mount
@@ -19,6 +19,13 @@ export interface AlfaFactoryOption extends IAppConfig {
19
19
  css?: Record<string, string>;
20
20
  js?: Record<string, string>;
21
21
  };
22
+ /**
23
+ * 关闭缓存模式
24
+ */
25
+ noCache?: boolean;
26
+ /**
27
+ * 开启业务配置加载
28
+ */
22
29
  dynamicConfig?: boolean;
23
30
  runtimeVersion?: string;
24
31
  fallbackRender?: (error: Error) => Element;
@@ -1 +1,5 @@
1
1
  export declare const normalizeName: (name: string) => string;
2
+ /**
3
+ * 判断是否在沙箱环境中运行
4
+ */
5
+ export declare const isOsContext: () => boolean;
@@ -1 +1 @@
1
- export declare const version = "1.4.29";
1
+ export declare const version = "1.4.30-alpha.1";
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Alibaba Cloud
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.