@micro-zoe/micro-app 1.0.0-rc.6 → 1.0.0-rc.7

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.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.6';
1
+ const version = '1.0.0-rc.7';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -4752,12 +4752,12 @@ function updateMicroLocation(appName, targetFullPath, microLocation, type) {
4752
4752
  microLocation.self.href = targetHref;
4753
4753
  }
4754
4754
  /**
4755
- * native模式从state中取值,而浏览器地址的修改无法控制,很可能出现浏览器地址和__MICRO_APP_STATE__不一致的情况
4756
- * 尤其是在初始化和前进后退时,由于vue-router4会主动修改url地址,倒是上述情况经常出现
4757
- * 为了结局这个问题,在子应用初始化和响应popstate事件后,判断__MICRO_APP_STATE__和浏览器地址是否一致,如果不一致,则将浏览器地址更新为__MICRO_APP_STATE__的地址
4758
- * 说明:
4759
- * 1、如果__MICRO_APP_STATE__和url不一样,那么更新url的操作是对的,否则会产生url和渲染页面不一致的问题,开发者会更加困惑
4760
- * 2、当native模式有多个子应用同时存在,其中一个修改url地址,另外一个并不会改变__MICRO_APP_STATE__,刷新就产生问题,不一致,第二是根据谁更新url?
4755
+ * The native mode also base of history.state, and the modification of the browser url cannot be controlled. It is very likely that the browser url and __MICRO_APP_STATE__ are different.
4756
+ * Especially during init of child or forward and backward of browser, because vue-router@4 will actively modify the browser URL, the above situation often occurs
4757
+ * To solve this problem, after child app is initialized and responds to the popstateEvent, it is determined whether __MICRO_APP_STATE__ and the browser url are different. If they are different, the browser url will updated to the address of __MICRO_APP_STATE__
4758
+ * NOTE:
4759
+ * 1. If __MICRO_APP_STATE__ is different from the URL, then the operation of updating the URL is correct, otherwise there will be a problem of inconsistency between the URL and the rendered page
4760
+ * 2. When there are multiple child app in native mode, if one of them changes the URL address, the other one will not change __MICRO_APP_STATE__, and refresh browser will cause problems
4761
4761
  */
4762
4762
  const rawLocation = globalEnv.rawWindow.location;
4763
4763
  if (isRouterModeCustom(appName) &&
@@ -5848,14 +5848,26 @@ function patchDocumentPrototype(appName, microAppWindow) {
5848
5848
  }
5849
5849
  // query element👇
5850
5850
  function querySelector(selectors) {
5851
- var _a, _b, _c;
5851
+ var _a;
5852
5852
  const _this = getBindTarget(this);
5853
5853
  if (!selectors ||
5854
5854
  isUniqueElement(selectors) ||
5855
5855
  rawDocument !== _this) {
5856
5856
  return rawMicroQuerySelector.call(_this, selectors);
5857
5857
  }
5858
- return (_c = (_b = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.querySelector(selectors)) !== null && _b !== void 0 ? _b : rawMicroQuerySelector.call(microDocument, selectors)) !== null && _c !== void 0 ? _c : null;
5858
+ /**
5859
+ * The child app cannot query the base element inside iframe
5860
+ * Same for querySelectorAll
5861
+ *
5862
+ * Scenes:
5863
+ * 1. vue-router@4.x --> createWebHistory(base?: string)
5864
+ * const baseEl = document.querySelector('base')
5865
+ * base = (baseEl && baseEl.getAttribute('href')) || '/'
5866
+ *
5867
+ * Issue: https://github.com/micro-zoe/micro-app/issues/1335
5868
+ */
5869
+ const result = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.querySelector(selectors);
5870
+ return result || selectors === 'base' ? result : rawMicroQuerySelector.call(microDocument, selectors);
5859
5871
  }
5860
5872
  function querySelectorAll(selectors) {
5861
5873
  var _a, _b;
@@ -5866,7 +5878,7 @@ function patchDocumentPrototype(appName, microAppWindow) {
5866
5878
  return rawMicroQuerySelectorAll.call(_this, selectors);
5867
5879
  }
5868
5880
  const result = (_b = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selectors)) !== null && _b !== void 0 ? _b : [];
5869
- return result.length ? result : rawMicroQuerySelectorAll.call(microDocument, selectors);
5881
+ return result.length || selectors === 'base' ? result : rawMicroQuerySelectorAll.call(microDocument, selectors);
5870
5882
  }
5871
5883
  microRootDocument.prototype.querySelector = querySelector;
5872
5884
  microRootDocument.prototype.querySelectorAll = querySelectorAll;
@@ -5899,8 +5911,9 @@ function patchDocumentPrototype(appName, microAppWindow) {
5899
5911
  if (isUniqueElement(key) ||
5900
5912
  isInvalidQuerySelectorKey(key)) {
5901
5913
  return rawMicroGetElementsByTagName.call(_this, key);
5914
+ // just script, not base
5902
5915
  }
5903
- else if (/^script|base$/i.test(key)) {
5916
+ else if (/^script$/i.test(key)) {
5904
5917
  return rawMicroGetElementsByTagName.call(microDocument, key);
5905
5918
  }
5906
5919
  try {
@@ -6366,7 +6379,7 @@ class IframeSandbox {
6366
6379
  this.escapeProperties = [];
6367
6380
  // Properties escape to rawWindow, cleared when unmount
6368
6381
  this.escapeKeys = new Set();
6369
- // 初始化和每次跳转时都要更新basehref
6382
+ // Update the base.href when initial and each redirect
6370
6383
  this.updateIframeBase = () => {
6371
6384
  var _a;
6372
6385
  // origin must be child app origin