@alicloud/alfa-react 1.4.30-alpha.0 → 1.4.30-alpha.2

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
@@ -41,7 +41,9 @@ export default function createApplication(loader) {
41
41
  customSandbox = props.sandbox,
42
42
  locale = props.locale,
43
43
  dynamicConfig = props.dynamicConfig,
44
- noCache = props.noCache;
44
+ noCache = props.noCache,
45
+ puppeteer = props.puppeteer,
46
+ basename = props.basename;
45
47
 
46
48
  var _useState = useState(null),
47
49
  _useState2 = _slicedToArray(_useState, 2),
@@ -53,7 +55,12 @@ export default function createApplication(loader) {
53
55
  setError = _useState4[1];
54
56
 
55
57
  var appRef = useRef(undefined);
58
+ var $puppeteer = useRef(puppeteer);
59
+ var $basename = useRef(basename);
56
60
  var tagName = normalizeName(props.name);
61
+ $puppeteer.current = puppeteer;
62
+ $basename.current = basename;
63
+ if ($puppeteer.current) customProps.consoleBase = null;
57
64
  var sandbox = useMemo(function () {
58
65
  var _UA_Opt, _RISK_INFO, _um;
59
66
 
@@ -107,11 +114,13 @@ export default function createApplication(loader) {
107
114
  useEffect(function () {
108
115
  var isUnmounted = false;
109
116
  var App;
117
+ var originalPushState;
118
+ var originalReplaceState;
110
119
 
111
120
  _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
112
- var _app$context$updateBo, _app$context;
121
+ var _app$context$updateBo, _app$context, _app$context$baseFram;
113
122
 
114
- var _yield$loader$registe, app, logger;
123
+ var _yield$loader$registe, app, logger, _ref2, path, frameWindow;
115
124
 
116
125
  return _regeneratorRuntime.wrap(function _callee$(_context) {
117
126
  while (1) {
@@ -160,15 +169,38 @@ export default function createApplication(loader) {
160
169
  case 12:
161
170
  // update body in sandbox context
162
171
  (_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);
163
- _context.next = 15;
172
+ _ref2 = memoOptions.props, path = _ref2.path;
173
+ frameWindow = (_app$context$baseFram = app.context.baseFrame) === null || _app$context$baseFram === void 0 ? void 0 : _app$context$baseFram.contentWindow;
174
+
175
+ if (frameWindow) {
176
+ originalPushState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.pushState;
177
+ originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState; // update context history according to path
178
+
179
+ if (path) originalReplaceState(null, '', path);
180
+
181
+ if ($puppeteer.current && frameWindow) {
182
+ frameWindow.history.pushState = function (data, unused, _url) {
183
+ window.history.pushState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
184
+ originalReplaceState(data, unused, _url);
185
+ };
186
+
187
+ frameWindow.history.replaceState = function (data, unused, _url) {
188
+ window.history.replaceState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
189
+ originalReplaceState(data, unused, _url);
190
+ };
191
+ }
192
+ }
193
+
194
+ _context.next = 18;
164
195
  return app.mount(appRef.current, {
165
196
  customProps: customProps
166
197
  });
167
198
 
168
- case 15:
199
+ case 18:
200
+ // just run once
169
201
  setAppInstance(app);
170
202
 
171
- case 16:
203
+ case 19:
172
204
  case "end":
173
205
  return _context.stop();
174
206
  }
@@ -181,12 +213,16 @@ export default function createApplication(loader) {
181
213
  });
182
214
 
183
215
  return function () {
184
- var _App;
216
+ var _App$context$baseFram;
185
217
 
186
218
  isUnmounted = true;
187
- App && App.unmount(); // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
219
+ if (!App) return;
220
+ App.unmount();
221
+ var frameWindow = (_App$context$baseFram = App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : _App$context$baseFram.contentWindow;
222
+ if (frameWindow && originalPushState) frameWindow.history.pushState = originalPushState;
223
+ if (frameWindow && originalReplaceState) frameWindow.history.pushState = originalReplaceState; // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
188
224
 
189
- if (isOsContext()) (_App = App) === null || _App === void 0 ? void 0 : _App.destroy();
225
+ if (isOsContext()) App.destroy();
190
226
  };
191
227
  }, [memoOptions]);
192
228
 
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.4.30-alpha.0';
1
+ export var version = '1.4.30-alpha.2';
@@ -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
@@ -63,7 +63,9 @@ function createApplication(loader) {
63
63
  customSandbox = props.sandbox,
64
64
  locale = props.locale,
65
65
  dynamicConfig = props.dynamicConfig,
66
- noCache = props.noCache;
66
+ noCache = props.noCache,
67
+ puppeteer = props.puppeteer,
68
+ basename = props.basename;
67
69
 
68
70
  var _useState = (0, _react.useState)(null),
69
71
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -75,7 +77,12 @@ function createApplication(loader) {
75
77
  setError = _useState4[1];
76
78
 
77
79
  var appRef = (0, _react.useRef)(undefined);
80
+ var $puppeteer = (0, _react.useRef)(puppeteer);
81
+ var $basename = (0, _react.useRef)(basename);
78
82
  var tagName = (0, _utils.normalizeName)(props.name);
83
+ $puppeteer.current = puppeteer;
84
+ $basename.current = basename;
85
+ if ($puppeteer.current) customProps.consoleBase = null;
79
86
  var sandbox = (0, _react.useMemo)(function () {
80
87
  var _UA_Opt, _RISK_INFO, _um;
81
88
 
@@ -129,10 +136,12 @@ function createApplication(loader) {
129
136
  (0, _react.useEffect)(function () {
130
137
  var isUnmounted = false;
131
138
  var App;
139
+ var originalPushState;
140
+ var originalReplaceState;
132
141
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
133
- var _app$context$updateBo, _app$context;
142
+ var _app$context$updateBo, _app$context, _app$context$baseFram;
134
143
 
135
- var _yield$loader$registe, app, logger;
144
+ var _yield$loader$registe, app, logger, _ref2, path, frameWindow;
136
145
 
137
146
  return _regenerator.default.wrap(function _callee$(_context) {
138
147
  while (1) {
@@ -181,15 +190,38 @@ function createApplication(loader) {
181
190
  case 12:
182
191
  // update body in sandbox context
183
192
  (_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);
184
- _context.next = 15;
193
+ _ref2 = memoOptions.props, path = _ref2.path;
194
+ frameWindow = (_app$context$baseFram = app.context.baseFrame) === null || _app$context$baseFram === void 0 ? void 0 : _app$context$baseFram.contentWindow;
195
+
196
+ if (frameWindow) {
197
+ originalPushState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.pushState;
198
+ originalReplaceState = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.replaceState; // update context history according to path
199
+
200
+ if (path) originalReplaceState(null, '', path);
201
+
202
+ if ($puppeteer.current && frameWindow) {
203
+ frameWindow.history.pushState = function (data, unused, _url) {
204
+ window.history.pushState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
205
+ originalReplaceState(data, unused, _url);
206
+ };
207
+
208
+ frameWindow.history.replaceState = function (data, unused, _url) {
209
+ window.history.replaceState(data, unused, "".concat($basename.current || '', "/").concat(_url).replace(/\/\//g, '/'));
210
+ originalReplaceState(data, unused, _url);
211
+ };
212
+ }
213
+ }
214
+
215
+ _context.next = 18;
185
216
  return app.mount(appRef.current, {
186
217
  customProps: customProps
187
218
  });
188
219
 
189
- case 15:
220
+ case 18:
221
+ // just run once
190
222
  setAppInstance(app);
191
223
 
192
- case 16:
224
+ case 19:
193
225
  case "end":
194
226
  return _context.stop();
195
227
  }
@@ -201,12 +233,16 @@ function createApplication(loader) {
201
233
  });
202
234
  });
203
235
  return function () {
204
- var _App;
236
+ var _App$context$baseFram;
205
237
 
206
238
  isUnmounted = true;
207
- App && App.unmount(); // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
239
+ if (!App) return;
240
+ App.unmount();
241
+ var frameWindow = (_App$context$baseFram = App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : _App$context$baseFram.contentWindow;
242
+ if (frameWindow && originalPushState) frameWindow.history.pushState = originalPushState;
243
+ if (frameWindow && originalReplaceState) frameWindow.history.pushState = originalReplaceState; // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
208
244
 
209
- if ((0, _utils.isOsContext)()) (_App = App) === null || _App === void 0 ? void 0 : _App.destroy();
245
+ if ((0, _utils.isOsContext)()) App.destroy();
210
246
  };
211
247
  }, [memoOptions]);
212
248
 
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.30-alpha.0';
7
+ var version = '1.4.30-alpha.2';
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.30-alpha.0",
3
+ "version": "1.4.30-alpha.2",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -51,5 +51,5 @@
51
51
  "peerDependencies": {
52
52
  "react": ">=16.0.0"
53
53
  },
54
- "gitHead": "971f337e52ca2ea36090f1e6f0fc6c57bb715a06"
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
@@ -1 +1 @@
1
- export declare const version = "1.4.30-alpha.0";
1
+ export declare const version = "1.4.30-alpha.2";
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.