@lemon-fe/vite-plugin-micro-frontend 1.0.9 → 1.1.0

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/dist/runtime.d.ts CHANGED
@@ -35,7 +35,6 @@ interface DynamicOptions<P = Record<string, unknown>> {
35
35
  }
36
36
  /**
37
37
  * 封装动态导入函数,兼容 Umi 的 dynamic
38
- *
39
38
  */
40
39
  declare function dynamic<P = Record<string, unknown>>(options: DynamicOptions<P>): ComponentType<P>;
41
40
 
package/dist/runtime.js CHANGED
@@ -1,4 +1,4 @@
1
- import require$$0, { createElement, Suspense, lazy, Component } from 'react';
1
+ import require$$0, { lazy, createElement, Suspense, Component } from 'react';
2
2
  import { qiankunWindow as qiankunWindow$1, renderWithQiankun as renderWithQiankun$1 } from 'vite-plugin-qiankun/es/helper';
3
3
 
4
4
  function getDefaultExportFromCjs (x) {
@@ -27877,15 +27877,16 @@ class DynamicErrorBoundary extends Component {
27877
27877
  }
27878
27878
  /**
27879
27879
  * 封装动态导入函数,兼容 Umi 的 dynamic
27880
- *
27881
27880
  */
27882
27881
  function dynamic(options) {
27882
+ // lazy 在外层调用,只创建一次,保证组件引用稳定(keepAlive 依赖此特性)
27883
+ const LazyComponent = lazy(options.loader);
27883
27884
  const LoadingComponent = options.loading;
27884
27885
  return function DynamicComponent(props) {
27885
27886
  const loadingElement = LoadingComponent
27886
27887
  ? createElement(LoadingComponent)
27887
27888
  : null;
27888
- return createElement(DynamicErrorBoundary, { LoadingComponent }, createElement(Suspense, { fallback: loadingElement }, createElement(lazy(options.loader), props)));
27889
+ return createElement(DynamicErrorBoundary, { LoadingComponent }, createElement(Suspense, { fallback: loadingElement }, createElement(LazyComponent, props)));
27889
27890
  };
27890
27891
  }
27891
27892