@umijs/plugins 4.0.7 → 4.0.10

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;
@@ -13,7 +13,7 @@ export type App = {
13
13
  // 取 entry 时是否需要开启跨域 credentials
14
14
  credentials?: boolean;
15
15
  props?: any;
16
- } & Pick<BaseIConfig, 'mountElementId'>;
16
+ } & Partial<Pick<BaseIConfig, 'mountElementId'>>;
17
17
 
18
18
  export type MicroAppRoute = {
19
19
  path: string;
@@ -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,7 +73,7 @@ export function genMount(mountElementId: string) {
73
73
  await slaveRuntime.mount(props);
74
74
  }
75
75
 
76
- const { type, ...historyOpts } = props?.history;
76
+ const { type, ...historyOpts } = props?.history || {};
77
77
 
78
78
  // 更新 clientRender 配置
79
79
  const clientRenderOpts = {
@@ -149,12 +149,20 @@ export function genUpdate() {
149
149
 
150
150
  export function genUnmount(mountElementId: string) {
151
151
  return async (props: any) => {
152
- const container = props?.container
153
- ? props.container.querySelector(`#${mountElementId}`)
154
- : document.getElementById(mountElementId);
155
- if (container) {
156
- 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
+ }
157
164
  }
165
+
158
166
  const slaveRuntime = await getSlaveRuntime();
159
167
  if (slaveRuntime.unmount) await slaveRuntime.unmount(props);
160
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.7",
3
+ "version": "4.0.10",
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.7",
27
+ "@ant-design/pro-layout": "^7.0.1-beta.28",
28
+ "@umijs/bundler-utils": "4.0.10",
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.7"
47
+ "umi": "4.0.10"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"