@umijs/plugins 4.0.6 → 4.0.9

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.
@@ -88,9 +88,16 @@ export const MicroApp = forwardRef(
88
88
  ...propsFromParams
89
89
  } = componentProps;
90
90
 
91
- // 优先使用 alias 名匹配,fallback 到 name 匹配
92
- const name = componentProps[appNameKeyAlias] || componentProps.name;
93
- const isCurrentApp = (app: any) => app[appNameKeyAlias] === name || app.name === name;
91
+ // ref: https://github.com/umijs/plugins/pull/866
92
+ // name appNameKeyAlias 这两个 key 同时存在时,优先使用 name,避免对存量应用造成 breaking change。
93
+ // 比如 appNameKeyAlias 配置是 id,但之前 id 正好作为普通的 props 使用过,如 <MicroApp name="app" id="123" />
94
+ // 正常场景会优先匹配 appNameKeyAlias 对应的字段,fallback 到 name,避免对已经使用 <MicroApp name="app" /> 的应用造成影响
95
+ const name =
96
+ componentProps.name && componentProps[appNameKeyAlias]
97
+ ? componentProps.name
98
+ : componentProps[appNameKeyAlias] || componentProps.name;
99
+ const isCurrentApp = (app: any) =>
100
+ app[appNameKeyAlias] === name || app.name === name;
94
101
 
95
102
  const [loading, setLoading] = useState(true);
96
103
  const [error, setError] = useState<any>(null);
@@ -143,13 +150,6 @@ export const MicroApp = forwardRef(
143
150
  setComponentError(null);
144
151
  setLoading(true);
145
152
  const configuration = {
146
- fetch(url) {
147
- return window.fetch(url, {
148
- headers: {
149
- accept: 'text/html',
150
- },
151
- });
152
- },
153
153
  globalContext: window,
154
154
  ...globalSettings,
155
155
  ...settingsFromProps,
@@ -178,11 +178,16 @@ export const MicroApp = forwardRef(
178
178
  if (noneMounted) {
179
179
  if (Array.isArray(prefetch)) {
180
180
  const specialPrefetchApps = apps.filter(
181
- (app) => !isCurrentApp(app) && (prefetch.indexOf(app[appNameKeyAlias]) !== -1 || prefetch.indexOf(app.name) !== -1)
181
+ (app) =>
182
+ !isCurrentApp(app) &&
183
+ (prefetch.indexOf(app[appNameKeyAlias]) !== -1 ||
184
+ prefetch.indexOf(app.name) !== -1),
182
185
  );
183
186
  prefetchApps(specialPrefetchApps, configuration);
184
187
  } else {
185
- const otherNotMountedApps = apps.filter((app) => !isCurrentApp(app));
188
+ const otherNotMountedApps = apps.filter(
189
+ (app) => !isCurrentApp(app),
190
+ );
186
191
  prefetchApps(otherNotMountedApps, configuration);
187
192
  }
188
193
  noneMounted = false;
@@ -1,7 +1,7 @@
1
1
  // @ts-nocheck
2
2
  import { getPluginManager } from '@@/core/plugin';
3
3
  import ReactDOM from 'react-dom';
4
- import { ApplyPluginsType } from 'umi';
4
+ import { ApplyPluginsType, __getRoot } from 'umi';
5
5
  import { setModelState } from './qiankunModel';
6
6
 
7
7
  const noop = () => {};
@@ -73,6 +73,8 @@ export function genMount(mountElementId: string) {
73
73
  await slaveRuntime.mount(props);
74
74
  }
75
75
 
76
+ const { type, ...historyOpts } = props?.history || {};
77
+
76
78
  // 更新 clientRender 配置
77
79
  const clientRenderOpts = {
78
80
  // 默认开启
@@ -95,6 +97,10 @@ export function genMount(mountElementId: string) {
95
97
 
96
98
  basename: props.base,
97
99
 
100
+ // 支持 MicroAppWithMemoHistory 需要
101
+ historyType: type,
102
+ historyOpts: historyOpts,
103
+
98
104
  // 当存在同一个 umi 子应用在同一个页面被多实例渲染的场景时(比如一个页面里,同时展示了这个子应用的多个路由页面)
99
105
  // mount 钩子会被调用多次,但是具体什么时候对应的实例开始 render 则是不定的,即它调用 applyPlugins('modifyClientRenderOpts') 的时机是不确定的
100
106
  // 为了保证每次 applyPlugins('modifyClientRenderOpts') 调用是生成正确的 history,我们需要这里通过闭包上下文维持 mount 调用时的一些配置信息
@@ -143,12 +149,20 @@ export function genUpdate() {
143
149
 
144
150
  export function genUnmount(mountElementId: string) {
145
151
  return async (props: any) => {
146
- const container = props?.container
147
- ? props.container.querySelector(`#${mountElementId}`)
148
- : document.getElementById(mountElementId);
149
- if (container) {
150
- ReactDOM.unmountComponentAtNode(container);
152
+ const root = __getRoot();
153
+
154
+ // support react 18 unmount
155
+ if (typeof root?.unmount === 'function') {
156
+ root.unmount();
157
+ } else {
158
+ const container = props?.container
159
+ ? props.container.querySelector(`#${mountElementId}`)
160
+ : document.getElementById(mountElementId);
161
+ if (container) {
162
+ ReactDOM.unmountComponentAtNode(container);
163
+ }
151
164
  }
165
+
152
166
  const slaveRuntime = await getSlaveRuntime();
153
167
  if (slaveRuntime.unmount) await slaveRuntime.unmount(props);
154
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.6",
3
+ "version": "4.0.9",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -16,16 +16,16 @@
16
16
  "libs"
17
17
  ],
18
18
  "scripts": {
19
- "build": "pnpm tsc",
19
+ "build": "umi-scripts father build",
20
20
  "build:deps": "umi-scripts bundleDeps",
21
- "dev": "pnpm build --watch",
21
+ "dev": "umi-scripts father dev",
22
22
  "test": "umi-scripts jest-turbo"
23
23
  },
24
24
  "dependencies": {
25
25
  "@ahooksjs/use-request": "^2.0.0",
26
26
  "@ant-design/icons": "^4.7.0",
27
- "@ant-design/pro-layout": "^7.0.1-beta.20",
28
- "@umijs/bundler-utils": "4.0.6",
27
+ "@ant-design/pro-layout": "^7.0.1-beta.28",
28
+ "@umijs/bundler-utils": "4.0.9",
29
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
30
  "axios": "^0.27.2",
31
31
  "babel-plugin-import": "^1.13.5",
@@ -44,7 +44,7 @@
44
44
  "warning": "^4.0.3"
45
45
  },
46
46
  "devDependencies": {
47
- "umi": "4.0.6"
47
+ "umi": "4.0.9"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"