@alicloud/alfa-react 1.4.30-alpha.0 → 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
@@ -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,11 @@ 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;
57
63
  var sandbox = useMemo(function () {
58
64
  var _UA_Opt, _RISK_INFO, _um;
59
65
 
@@ -107,11 +113,13 @@ export default function createApplication(loader) {
107
113
  useEffect(function () {
108
114
  var isUnmounted = false;
109
115
  var App;
116
+ var originalPushState;
117
+ var originalReplaceState;
110
118
 
111
119
  _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
112
- var _app$context$updateBo, _app$context;
120
+ var _app$context$updateBo, _app$context, _app$context$baseFram;
113
121
 
114
- var _yield$loader$registe, app, logger;
122
+ var _yield$loader$registe, app, logger, _ref2, path, frameWindow;
115
123
 
116
124
  return _regeneratorRuntime.wrap(function _callee$(_context) {
117
125
  while (1) {
@@ -160,15 +168,38 @@ export default function createApplication(loader) {
160
168
  case 12:
161
169
  // update body in sandbox context
162
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);
163
- _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;
164
194
  return app.mount(appRef.current, {
165
195
  customProps: customProps
166
196
  });
167
197
 
168
- case 15:
198
+ case 18:
199
+ // just run once
169
200
  setAppInstance(app);
170
201
 
171
- case 16:
202
+ case 19:
172
203
  case "end":
173
204
  return _context.stop();
174
205
  }
@@ -181,12 +212,16 @@ export default function createApplication(loader) {
181
212
  });
182
213
 
183
214
  return function () {
184
- var _App;
215
+ var _App$context$baseFram;
185
216
 
186
217
  isUnmounted = true;
187
- 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; // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
188
223
 
189
- if (isOsContext()) (_App = App) === null || _App === void 0 ? void 0 : _App.destroy();
224
+ if (isOsContext()) App.destroy();
190
225
  };
191
226
  }, [memoOptions]);
192
227
 
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.4.30-alpha.0';
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
@@ -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,11 @@ 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;
79
85
  var sandbox = (0, _react.useMemo)(function () {
80
86
  var _UA_Opt, _RISK_INFO, _um;
81
87
 
@@ -129,10 +135,12 @@ function createApplication(loader) {
129
135
  (0, _react.useEffect)(function () {
130
136
  var isUnmounted = false;
131
137
  var App;
138
+ var originalPushState;
139
+ var originalReplaceState;
132
140
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
133
- var _app$context$updateBo, _app$context;
141
+ var _app$context$updateBo, _app$context, _app$context$baseFram;
134
142
 
135
- var _yield$loader$registe, app, logger;
143
+ var _yield$loader$registe, app, logger, _ref2, path, frameWindow;
136
144
 
137
145
  return _regenerator.default.wrap(function _callee$(_context) {
138
146
  while (1) {
@@ -181,15 +189,38 @@ function createApplication(loader) {
181
189
  case 12:
182
190
  // update body in sandbox context
183
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);
184
- _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;
185
215
  return app.mount(appRef.current, {
186
216
  customProps: customProps
187
217
  });
188
218
 
189
- case 15:
219
+ case 18:
220
+ // just run once
190
221
  setAppInstance(app);
191
222
 
192
- case 16:
223
+ case 19:
193
224
  case "end":
194
225
  return _context.stop();
195
226
  }
@@ -201,12 +232,16 @@ function createApplication(loader) {
201
232
  });
202
233
  });
203
234
  return function () {
204
- var _App;
235
+ var _App$context$baseFram;
205
236
 
206
237
  isUnmounted = true;
207
- 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; // 在沙箱中嵌套时,必须销毁实例,避免第二次加载时异常
208
243
 
209
- if ((0, _utils.isOsContext)()) (_App = App) === null || _App === void 0 ? void 0 : _App.destroy();
244
+ if ((0, _utils.isOsContext)()) App.destroy();
210
245
  };
211
246
  }, [memoOptions]);
212
247
 
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.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.30-alpha.0",
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",
@@ -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.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.