@micro-zoe/micro-app 1.0.0-rc.1 → 1.0.0-rc.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.
package/lib/index.d.ts CHANGED
@@ -309,7 +309,21 @@ declare module '@micro-zoe/micro-app/libs/utils' {
309
309
  * @param args arguments
310
310
  */
311
311
  export function execMicroAppGlobalHook(fn: Func | null, appName: string, hookName: string, ...args: unknown[]): void;
312
+ /**
313
+ * remove all childNode from target node
314
+ * @param $dom target node
315
+ */
312
316
  export function clearDOM($dom: HTMLElement | ShadowRoot | Document): void;
317
+ type BaseHTMLElementType = HTMLElement & {
318
+ new (): HTMLElement;
319
+ prototype: HTMLElement;
320
+ };
321
+ /**
322
+ * get HTMLElement from base app
323
+ * @returns HTMLElement
324
+ */
325
+ export function getBaseHTMLElement(): BaseHTMLElementType;
326
+ export {};
313
327
  }
314
328
 
315
329
  declare module '@micro-zoe/micro-app/interact' {
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.1';
1
+ const version = '1.0.0-rc.2';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -344,7 +344,7 @@ function removeDomScope() {
344
344
  * Create pure elements
345
345
  */
346
346
  function pureCreateElement(tagName, options) {
347
- const element = document.createElement(tagName, options);
347
+ const element = (window.rawDocument || document).createElement(tagName, options);
348
348
  if (element.__MICRO_APP_NAME__)
349
349
  delete element.__MICRO_APP_NAME__;
350
350
  element.__PURE_ELEMENT__ = true;
@@ -550,11 +550,23 @@ function execMicroAppGlobalHook(fn, appName, hookName, ...args) {
550
550
  logError(`An error occurred in app ${appName} window.${hookName} \n`, null, e);
551
551
  }
552
552
  }
553
+ /**
554
+ * remove all childNode from target node
555
+ * @param $dom target node
556
+ */
553
557
  function clearDOM($dom) {
554
558
  while ($dom === null || $dom === void 0 ? void 0 : $dom.firstChild) {
555
559
  $dom.removeChild($dom.firstChild);
556
560
  }
557
561
  }
562
+ /**
563
+ * get HTMLElement from base app
564
+ * @returns HTMLElement
565
+ */
566
+ function getBaseHTMLElement() {
567
+ var _a;
568
+ return (((_a = window.rawWindow) === null || _a === void 0 ? void 0 : _a.HTMLElement) || window.HTMLElement);
569
+ }
558
570
 
559
571
  function formatEventInfo(event, element) {
560
572
  Object.defineProperties(event, {
@@ -1524,8 +1536,7 @@ function isInlineMode(app, scriptInfo) {
1524
1536
  return (app.inline ||
1525
1537
  scriptInfo.appSpace[app.name].inline ||
1526
1538
  isTypeModule(app, scriptInfo) ||
1527
- isSpecialScript(app, scriptInfo) ||
1528
- app.iframe);
1539
+ isSpecialScript(app, scriptInfo));
1529
1540
  }
1530
1541
  // TODO: iframe重新插入window前后不一致,通过iframe Function创建的函数无法复用
1531
1542
  function getEffectWindow(app) {
@@ -2687,148 +2698,6 @@ function bindFunctionToRawTarget(value, rawTarget, key = 'WINDOW') {
2687
2698
  return value;
2688
2699
  }
2689
2700
 
2690
- class Adapter {
2691
- constructor() {
2692
- // keys that can only assigned to rawWindow
2693
- this.escapeSetterKeyList = [
2694
- 'location',
2695
- ];
2696
- // keys that can escape to rawWindow
2697
- this.staticEscapeProperties = [
2698
- 'System',
2699
- '__cjsWrapper',
2700
- ];
2701
- // keys that scoped in child app
2702
- this.staticScopeProperties = [
2703
- 'webpackJsonp',
2704
- 'webpackHotUpdate',
2705
- 'Vue',
2706
- ];
2707
- this.injectReactHMRProperty();
2708
- }
2709
- // adapter for react
2710
- injectReactHMRProperty() {
2711
- if ((process.env.NODE_ENV !== 'production')) {
2712
- // react child in non-react env
2713
- this.staticEscapeProperties.push('__REACT_ERROR_OVERLAY_GLOBAL_HOOK__');
2714
- // in react parent
2715
- if (globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__) {
2716
- this.staticScopeProperties = this.staticScopeProperties.concat([
2717
- '__REACT_ERROR_OVERLAY_GLOBAL_HOOK__',
2718
- '__reactRefreshInjected',
2719
- ]);
2720
- }
2721
- }
2722
- }
2723
- }
2724
- // Fix conflict of babel-polyfill@6.x
2725
- function fixBabelPolyfill6() {
2726
- if (globalEnv.rawWindow._babelPolyfill)
2727
- globalEnv.rawWindow._babelPolyfill = false;
2728
- }
2729
- /**
2730
- * Fix error of hot reload when parent&child created by create-react-app in development environment
2731
- * Issue: https://github.com/micro-zoe/micro-app/issues/382
2732
- */
2733
- function fixReactHMRConflict(app) {
2734
- var _a;
2735
- if ((process.env.NODE_ENV !== 'production')) {
2736
- const rawReactErrorHook = globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__;
2737
- const childReactErrorHook = (_a = app.sandBox) === null || _a === void 0 ? void 0 : _a.proxyWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__;
2738
- if (rawReactErrorHook && childReactErrorHook) {
2739
- globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__ = childReactErrorHook;
2740
- defer(() => {
2741
- globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__ = rawReactErrorHook;
2742
- });
2743
- }
2744
- }
2745
- }
2746
- /**
2747
- * reDefine parentNode of html
2748
- * Scenes:
2749
- * 1. element-ui@2/lib/utils/popper.js
2750
- * var parent = element.parentNode;
2751
- * // root is child app window
2752
- * if (parent === root.document) ...
2753
- */
2754
- function throttleDeferForParentNode(microDocument) {
2755
- const html = globalEnv.rawDocument.firstElementChild;
2756
- if ((html === null || html === void 0 ? void 0 : html.parentNode) === globalEnv.rawDocument) {
2757
- setParentNode(html, microDocument);
2758
- defer(() => {
2759
- setParentNode(html, globalEnv.rawDocument);
2760
- });
2761
- }
2762
- }
2763
- /**
2764
- * Modify the point of parentNode
2765
- * @param target target Node
2766
- * @param value parentNode
2767
- */
2768
- function setParentNode(target, value) {
2769
- const descriptor = Object.getOwnPropertyDescriptor(target, 'parentNode');
2770
- if (!descriptor || descriptor.configurable) {
2771
- rawDefineProperty(target, 'parentNode', {
2772
- value,
2773
- configurable: true,
2774
- });
2775
- }
2776
- }
2777
- /**
2778
- * update dom tree of target dom
2779
- * @param container target dom
2780
- * @param appName app name
2781
- */
2782
- function patchElementTree(container, appName) {
2783
- const children = Array.from(container.children);
2784
- children.length && children.forEach((child) => {
2785
- patchElementTree(child, appName);
2786
- });
2787
- for (const child of children) {
2788
- updateElementInfo(child, appName);
2789
- }
2790
- }
2791
- /**
2792
- * rewrite baseURI, ownerDocument, __MICRO_APP_NAME__ of target node
2793
- * @param node target node
2794
- * @param appName app name
2795
- * @returns target node
2796
- */
2797
- function updateElementInfo(node, appName) {
2798
- var _a, _b;
2799
- const proxyWindow = (_b = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.sandBox) === null || _b === void 0 ? void 0 : _b.proxyWindow;
2800
- if (isNode(node) &&
2801
- !node.__MICRO_APP_NAME__ &&
2802
- !node.__PURE_ELEMENT__ &&
2803
- proxyWindow) {
2804
- /**
2805
- * TODO:
2806
- * 1. 测试baseURI和ownerDocument在with沙箱中是否正确
2807
- * 经过验证with沙箱不能重写ownerDocument,否则react点击事件会触发两次
2808
- * 2. with沙箱所有node设置__MICRO_APP_NAME__都使用updateElementInfo
2809
- * 3. 性能: defineProperty的性能肯定不如直接设置
2810
- */
2811
- rawDefineProperties(node, {
2812
- baseURI: {
2813
- configurable: true,
2814
- get: () => proxyWindow.location.href,
2815
- },
2816
- __MICRO_APP_NAME__: {
2817
- configurable: true,
2818
- writable: true,
2819
- value: appName,
2820
- },
2821
- });
2822
- if (isIframeSandbox(appName)) {
2823
- rawDefineProperty(node, 'ownerDocument', {
2824
- configurable: true,
2825
- get: () => proxyWindow.document,
2826
- });
2827
- }
2828
- }
2829
- return node;
2830
- }
2831
-
2832
2701
  /**
2833
2702
  * create proxyDocument and MicroDocument, rewrite document of child app
2834
2703
  * @param appName app name
@@ -2955,11 +2824,36 @@ function createProxyDocument(appName, sandbox) {
2955
2824
  eventListenerMap.clear();
2956
2825
  }
2957
2826
  };
2827
+ const genProxyDocumentProps = () => {
2828
+ var _a;
2829
+ // microApp framework built-in Proxy
2830
+ const builtInProxyProps = new Map([
2831
+ ['onclick', (value) => {
2832
+ if (isFunction(onClickHandler)) {
2833
+ rawRemoveEventListener.call(rawDocument, 'click', onClickHandler, false);
2834
+ }
2835
+ // TODO: listener 是否需要绑定proxyDocument,否则函数中的this指向原生window
2836
+ if (isFunction(value)) {
2837
+ rawAddEventListener.call(rawDocument, 'click', value, false);
2838
+ }
2839
+ onClickHandler = value;
2840
+ }]
2841
+ ]);
2842
+ // external custom proxy
2843
+ const customProxyDocumentProps = ((_a = microApp.options) === null || _a === void 0 ? void 0 : _a.customProxyDocumentProps) || new Map();
2844
+ // External has higher priority than built-in
2845
+ const mergedProxyDocumentProps = new Map([
2846
+ ...builtInProxyProps,
2847
+ ...customProxyDocumentProps,
2848
+ ]);
2849
+ return mergedProxyDocumentProps;
2850
+ };
2851
+ const mergedProxyDocumentProps = genProxyDocumentProps();
2958
2852
  const proxyDocument = new Proxy(rawDocument, {
2959
2853
  get: (target, key) => {
2960
2854
  var _a;
2961
2855
  throttleDeferForSetAppName(appName);
2962
- throttleDeferForParentNode(proxyDocument);
2856
+ // TODO: 转换成数据形式,类似iframe的方式
2963
2857
  if (key === 'createElement')
2964
2858
  return createElement;
2965
2859
  if (key === Symbol.toStringTag)
@@ -2974,18 +2868,14 @@ function createProxyDocument(appName, sandbox) {
2974
2868
  return removeEventListener;
2975
2869
  if (key === 'microAppElement')
2976
2870
  return (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.container;
2871
+ if (key === '__MICRO_APP_NAME__')
2872
+ return appName;
2977
2873
  return bindFunctionToRawTarget(Reflect.get(target, key), rawDocument, 'DOCUMENT');
2978
2874
  },
2979
2875
  set: (target, key, value) => {
2980
- if (key === 'onclick') {
2981
- if (isFunction(onClickHandler)) {
2982
- rawRemoveEventListener.call(rawDocument, 'click', onClickHandler, false);
2983
- }
2984
- // TODO: listener 是否需要绑定proxyDocument,否则函数中的this指向原生window
2985
- if (isFunction(value)) {
2986
- rawAddEventListener.call(rawDocument, 'click', value, false);
2987
- }
2988
- onClickHandler = value;
2876
+ if (mergedProxyDocumentProps.has(key)) {
2877
+ const proxyCallback = mergedProxyDocumentProps.get(key);
2878
+ proxyCallback(value);
2989
2879
  }
2990
2880
  else if (key !== 'microAppElement') {
2991
2881
  /**
@@ -3784,7 +3674,11 @@ function navigateWithNativeEvent(appName, methodName, result, onlyForBrowser, st
3784
3674
  const oldHref = result.isAttach2Hash && oldFullPath !== result.fullPath ? rawLocation.href : null;
3785
3675
  // navigate with native history method
3786
3676
  nativeHistoryNavigate(appName, methodName, result.fullPath, state, title);
3787
- // TODO: 如果所有模式统一发送popstate事件,则!isRouterModeCustom(appName)要去掉
3677
+ /**
3678
+ * TODO:
3679
+ * 1. 如果所有模式统一发送popstate事件,则!isRouterModeCustom(appName)要去掉
3680
+ * 2. 如果发送事件,则会导致vue router-view :key='router.path'绑定,无限卸载应用,死循环
3681
+ */
3788
3682
  if (oldFullPath !== result.fullPath && !isRouterModeCustom(appName)) {
3789
3683
  dispatchNativeEvent(appName, onlyForBrowser, oldHref);
3790
3684
  }
@@ -4540,6 +4434,117 @@ function removePathFromBrowser(appName) {
4540
4434
  attachRouteToBrowserURL(appName, removeMicroPathFromURL(appName), removeMicroState(appName, globalEnv.rawWindow.history.state));
4541
4435
  }
4542
4436
 
4437
+ class Adapter {
4438
+ constructor() {
4439
+ // keys that can only assigned to rawWindow
4440
+ this.escapeSetterKeyList = [
4441
+ 'location',
4442
+ ];
4443
+ // keys that can escape to rawWindow
4444
+ this.staticEscapeProperties = [
4445
+ 'System',
4446
+ '__cjsWrapper',
4447
+ ];
4448
+ // keys that scoped in child app
4449
+ this.staticScopeProperties = [
4450
+ 'webpackJsonp',
4451
+ 'webpackHotUpdate',
4452
+ 'Vue',
4453
+ ];
4454
+ this.injectReactHMRProperty();
4455
+ }
4456
+ // adapter for react
4457
+ injectReactHMRProperty() {
4458
+ if ((process.env.NODE_ENV !== 'production')) {
4459
+ // react child in non-react env
4460
+ this.staticEscapeProperties.push('__REACT_ERROR_OVERLAY_GLOBAL_HOOK__');
4461
+ // in react parent
4462
+ if (globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__) {
4463
+ this.staticScopeProperties = this.staticScopeProperties.concat([
4464
+ '__REACT_ERROR_OVERLAY_GLOBAL_HOOK__',
4465
+ '__reactRefreshInjected',
4466
+ ]);
4467
+ }
4468
+ }
4469
+ }
4470
+ }
4471
+ // Fix conflict of babel-polyfill@6.x
4472
+ function fixBabelPolyfill6() {
4473
+ if (globalEnv.rawWindow._babelPolyfill)
4474
+ globalEnv.rawWindow._babelPolyfill = false;
4475
+ }
4476
+ /**
4477
+ * Fix error of hot reload when parent&child created by create-react-app in development environment
4478
+ * Issue: https://github.com/micro-zoe/micro-app/issues/382
4479
+ */
4480
+ function fixReactHMRConflict(app) {
4481
+ var _a;
4482
+ if ((process.env.NODE_ENV !== 'production')) {
4483
+ const rawReactErrorHook = globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__;
4484
+ const childReactErrorHook = (_a = app.sandBox) === null || _a === void 0 ? void 0 : _a.proxyWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__;
4485
+ if (rawReactErrorHook && childReactErrorHook) {
4486
+ globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__ = childReactErrorHook;
4487
+ defer(() => {
4488
+ globalEnv.rawWindow.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__ = rawReactErrorHook;
4489
+ });
4490
+ }
4491
+ }
4492
+ }
4493
+ /**
4494
+ * update dom tree of target dom
4495
+ * @param container target dom
4496
+ * @param appName app name
4497
+ */
4498
+ function patchElementTree(container, appName) {
4499
+ const children = Array.from(container.children);
4500
+ children.length && children.forEach((child) => {
4501
+ patchElementTree(child, appName);
4502
+ });
4503
+ for (const child of children) {
4504
+ updateElementInfo(child, appName);
4505
+ }
4506
+ }
4507
+ /**
4508
+ * rewrite baseURI, ownerDocument, __MICRO_APP_NAME__ of target node
4509
+ * @param node target node
4510
+ * @param appName app name
4511
+ * @returns target node
4512
+ */
4513
+ function updateElementInfo(node, appName) {
4514
+ var _a, _b;
4515
+ const proxyWindow = (_b = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.sandBox) === null || _b === void 0 ? void 0 : _b.proxyWindow;
4516
+ if (isNode(node) &&
4517
+ !node.__MICRO_APP_NAME__ &&
4518
+ !node.__PURE_ELEMENT__ &&
4519
+ proxyWindow) {
4520
+ /**
4521
+ * TODO:
4522
+ * 1. 测试baseURI和ownerDocument在with沙箱中是否正确
4523
+ * 经过验证with沙箱不能重写ownerDocument,否则react点击事件会触发两次
4524
+ * 2. with沙箱所有node设置__MICRO_APP_NAME__都使用updateElementInfo
4525
+ * 3. 性能: defineProperty的性能肯定不如直接设置
4526
+ */
4527
+ rawDefineProperties(node, {
4528
+ baseURI: {
4529
+ configurable: true,
4530
+ get: () => proxyWindow.location.href,
4531
+ },
4532
+ __MICRO_APP_NAME__: {
4533
+ configurable: true,
4534
+ writable: true,
4535
+ value: appName,
4536
+ },
4537
+ });
4538
+ if (isIframeSandbox(appName)) {
4539
+ rawDefineProperty(node, 'ownerDocument', {
4540
+ configurable: true,
4541
+ get: () => proxyWindow.document,
4542
+ });
4543
+ }
4544
+ }
4545
+ return node;
4546
+ }
4547
+
4543
4548
  /**
4544
4549
  * https://developer.mozilla.org/en-US/docs/Web/API/fetch
4545
4550
  * Promise<Response> fetch(input[, init])
@@ -4934,7 +4939,7 @@ class WithSandBox {
4934
4939
  enumerable: false,
4935
4940
  get() {
4936
4941
  throttleDeferForSetAppName(appName);
4937
- return modifiedEval || eval;
4942
+ return modifiedEval || globalEnv.rawWindow.eval;
4938
4943
  },
4939
4944
  set: (value) => {
4940
4945
  modifiedEval = value;
@@ -5368,17 +5373,18 @@ function patchDocumentPrototype(appName, microAppWindow) {
5368
5373
  }
5369
5374
  };
5370
5375
  microRootDocument.prototype.getElementsByTagName = function getElementsByTagName(key) {
5371
- var _a;
5372
5376
  const _this = getDefaultRawTarget(this);
5373
5377
  if (isUniqueElement(key) ||
5374
- isInvalidQuerySelectorKey(key) ||
5375
- (!((_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.inline) && /^script$/i.test(key))) {
5378
+ isInvalidQuerySelectorKey(key)) {
5376
5379
  return rawMicroGetElementsByTagName.call(_this, key);
5377
5380
  }
5381
+ else if (/^script|base$/i.test(key)) {
5382
+ return rawMicroGetElementsByTagName.call(microDocument, key);
5383
+ }
5378
5384
  try {
5379
5385
  return querySelectorAll.call(this, key);
5380
5386
  }
5381
- catch (_b) {
5387
+ catch (_a) {
5382
5388
  return rawMicroGetElementsByTagName.call(_this, key);
5383
5389
  }
5384
5390
  };
@@ -5421,6 +5427,7 @@ function patchDocumentProperty(appName, microAppWindow, sandbox) {
5421
5427
  ['links', () => microRootDocument.prototype.querySelectorAll.call(microDocument, 'a')],
5422
5428
  // unique keys of micro-app
5423
5429
  ['microAppElement', () => { var _a; return (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.container; }],
5430
+ ['__MICRO_APP_NAME__', () => appName],
5424
5431
  ];
5425
5432
  descList.forEach((desc) => {
5426
5433
  result[desc[0]] = getCommonDescriptor(desc[0], desc[1]);
@@ -5732,8 +5739,12 @@ function patchIframeNode(appName, microAppWindow, sandbox) {
5732
5739
  enumerable: true,
5733
5740
  get() {
5734
5741
  var _a, _b, _c;
5735
- // set html.parentNode to microDocument
5736
- throttleDeferForParentNode(microDocument);
5742
+ /**
5743
+ * set current appName for hijack parentNode of html
5744
+ * NOTE:
5745
+ * 1. Is there a problem with setting the current appName in iframe mode
5746
+ */
5747
+ throttleDeferForSetAppName(appName);
5737
5748
  const result = rawParentNodeLDesc.get.call(this);
5738
5749
  /**
5739
5750
  * If parentNode is <micro-app-body>, return rawDocument.body
@@ -6174,8 +6185,9 @@ class CreateApp {
6174
6185
  this.url = url;
6175
6186
  this.useSandbox = useSandbox;
6176
6187
  this.scopecss = this.useSandbox && scopecss;
6177
- this.inline = inline !== null && inline !== void 0 ? inline : false;
6188
+ // exec before getInlineModeState
6178
6189
  this.iframe = iframe !== null && iframe !== void 0 ? iframe : false;
6190
+ this.inline = this.getInlineModeState(inline);
6179
6191
  /**
6180
6192
  * NOTE:
6181
6193
  * 1. Navigate after micro-app created, before mount
@@ -6318,7 +6330,7 @@ class CreateApp {
6318
6330
  }
6319
6331
  else {
6320
6332
  this.container = container;
6321
- this.inline = inline;
6333
+ this.inline = this.getInlineModeState(inline);
6322
6334
  this.fiber = fiber;
6323
6335
  this.routerMode = routerMode;
6324
6336
  const dispatchBeforeMount = () => dispatchLifecyclesEvent(this.container, this.name, lifeCycles.BEFOREMOUNT);
@@ -6682,6 +6694,15 @@ class CreateApp {
6682
6694
  querySelectorAll(selectors) {
6683
6695
  return this.container ? globalEnv.rawElementQuerySelectorAll.call(this.container, selectors) : [];
6684
6696
  }
6697
+ /**
6698
+ * NOTE:
6699
+ * 1. If the iframe sandbox no longer enforces the use of inline mode in the future, the way getElementsByTagName retrieves the script from the iframe by default needs to be changed, because in non inline mode, the script in the iframe may be empty
6700
+ * @param inline inline mode config
6701
+ */
6702
+ getInlineModeState(inline) {
6703
+ var _a;
6704
+ return (_a = (this.iframe || inline)) !== null && _a !== void 0 ? _a : false;
6705
+ }
6685
6706
  }
6686
6707
  // iframe route mode
6687
6708
  function isIframeSandbox(appName) {
@@ -6917,6 +6938,7 @@ function commonElementHandler(parent, newChild, passiveChild, rawMethod) {
6917
6938
  function patchElementAndDocument() {
6918
6939
  patchDocument$2();
6919
6940
  const rawRootElement = globalEnv.rawRootElement;
6941
+ const rawRootNode = globalEnv.rawRootNode;
6920
6942
  // prototype methods of add element👇
6921
6943
  rawRootElement.prototype.appendChild = function appendChild(newChild) {
6922
6944
  return commonElementHandler(this, newChild, null, globalEnv.rawAppendChild);
@@ -7073,32 +7095,42 @@ function patchElementAndDocument() {
7073
7095
  });
7074
7096
  }
7075
7097
  });
7076
- /**
7077
- * NOTE:Abandon this way at 2023.2.28 before v1.0.0-beta.0, it will cause vue2 throw error when render again
7078
- */
7079
- // rawDefineProperty(Node.prototype, 'parentNode', {
7080
- // configurable: true,
7081
- // enumerable: true,
7082
- // get () {
7083
- // const result = globalEnv.rawParentNodeDesc.get.call(this)
7084
- // /**
7085
- // * If parentNode is <micro-app-body>, return rawDocument.body
7086
- // * Scenes:
7087
- // * 1. element-ui@2/lib/utils/vue-popper.js
7088
- // * if (this.popperElm.parentNode === document.body) ...
7089
- // * WARNING:
7090
- // * Will it cause other problems ?
7091
- // * e.g. target.parentNode.remove(target)
7092
- // * BUG:
7093
- // * 1. vue2 umdMode, throw error when render again (<div id='app'></div> will be deleted when render again )
7094
- // */
7095
- // if (isMicroAppBody(result) && appInstanceMap.get(this.__MICRO_APP_NAME__)?.container) {
7096
- // return document.body
7097
- // }
7098
- // return result
7099
- // },
7100
- // set: undefined,
7101
- // })
7098
+ rawDefineProperty(rawRootNode.prototype, 'parentNode', {
7099
+ configurable: true,
7100
+ enumerable: true,
7101
+ get() {
7102
+ var _a, _b, _c;
7103
+ /**
7104
+ * hijack parentNode of html
7105
+ * Scenes:
7106
+ * 1. element-ui@2/lib/utils/popper.js
7107
+ * // root is child app window, so root.document is proxyDocument or microDocument
7108
+ * if (element.parentNode === root.document) ...
7109
+ */
7110
+ const currentAppName = getCurrentAppName();
7111
+ if (currentAppName && this === globalEnv.rawDocument.firstElementChild) {
7112
+ const microDocument = (_c = (_b = (_a = appInstanceMap.get(currentAppName)) === null || _a === void 0 ? void 0 : _a.sandBox) === null || _b === void 0 ? void 0 : _b.proxyWindow) === null || _c === void 0 ? void 0 : _c.document;
7113
+ if (microDocument)
7114
+ return microDocument;
7115
+ }
7116
+ const result = globalEnv.rawParentNodeDesc.get.call(this);
7117
+ /**
7118
+ * If parentNode is <micro-app-body>, return rawDocument.body
7119
+ * Scenes:
7120
+ * 1. element-ui@2/lib/utils/vue-popper.js
7121
+ * if (this.popperElm.parentNode === document.body) ...
7122
+ * WARNING:
7123
+ * Will it cause other problems ?
7124
+ * e.g. target.parentNode.remove(target)
7125
+ * BUG:
7126
+ * 1. vue2 umdMode, throw error when render again (<div id='app'></div> will be deleted when render again ) -- Abandon this way at 2023.2.28 before v1.0.0-beta.0, it will cause vue2 throw error when render again
7127
+ */
7128
+ // if (isMicroAppBody(result) && appInstanceMap.get(this.__MICRO_APP_NAME__)?.container) {
7129
+ // return document.body
7130
+ // }
7131
+ return result;
7132
+ },
7133
+ });
7102
7134
  }
7103
7135
  /**
7104
7136
  * Mark the newly created element in the micro application
@@ -7237,6 +7269,7 @@ function releasePatchElementAndDocument() {
7237
7269
  removeDomScope();
7238
7270
  releasePatchDocument();
7239
7271
  const rawRootElement = globalEnv.rawRootElement;
7272
+ const rawRootNode = globalEnv.rawRootNode;
7240
7273
  rawRootElement.prototype.appendChild = globalEnv.rawAppendChild;
7241
7274
  rawRootElement.prototype.insertBefore = globalEnv.rawInsertBefore;
7242
7275
  rawRootElement.prototype.replaceChild = globalEnv.rawReplaceChild;
@@ -7248,6 +7281,7 @@ function releasePatchElementAndDocument() {
7248
7281
  rawRootElement.prototype.querySelectorAll = globalEnv.rawElementQuerySelectorAll;
7249
7282
  rawRootElement.prototype.setAttribute = globalEnv.rawSetAttribute;
7250
7283
  rawDefineProperty(rawRootElement.prototype, 'innerHTML', globalEnv.rawInnerHTMLDesc);
7284
+ rawDefineProperty(rawRootNode.prototype, 'parentNode', globalEnv.rawParentNodeDesc);
7251
7285
  }
7252
7286
  // Set the style of micro-app-head and micro-app-body
7253
7287
  let hasRejectMicroAppStyle = false;
@@ -7380,9 +7414,9 @@ function initGlobalEnv() {
7380
7414
  /**
7381
7415
  * define element
7382
7416
  * @param tagName element name
7383
- */
7417
+ */
7384
7418
  function defineElement(tagName) {
7385
- class MicroAppElement extends HTMLElement {
7419
+ class MicroAppElement extends getBaseHTMLElement() {
7386
7420
  constructor() {
7387
7421
  super(...arguments);
7388
7422
  this.isWaiting = false;