@blocklet/pages-kit 0.5.53 → 0.5.55
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.
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { cx } from '@emotion/css';
|
|
3
3
|
import { Skeleton, Fade, Box } from '@mui/material';
|
|
4
4
|
import isEmpty from 'lodash/isEmpty';
|
|
5
|
+
import omit from 'lodash/omit';
|
|
5
6
|
import set from 'lodash/set';
|
|
6
7
|
import { useDeferredValue, useEffect, useRef, useState, useMemo } from 'react';
|
|
7
8
|
import { Helmet } from 'react-helmet';
|
|
@@ -290,21 +291,25 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
|
|
|
290
291
|
const realLocale = getRealLocale(locale);
|
|
291
292
|
const result = getComponentByComponentId({ componentId, locale: realLocale, instanceId });
|
|
292
293
|
if (result) {
|
|
293
|
-
|
|
294
|
+
// 只缓存 props 以外的数据,props 会跟随语言动态更新
|
|
295
|
+
previousRef.current = omit(result, 'props');
|
|
294
296
|
return result;
|
|
295
297
|
}
|
|
296
298
|
if (instanceId) {
|
|
297
299
|
const key = [instanceId, realLocale].join('-');
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
300
|
+
const componentState = customComponentStates().getState();
|
|
301
|
+
COMPONENT_LOADER_MAP[key] ??=
|
|
302
|
+
Promise.resolve(componentState.getComponent({ componentId, locale: realLocale ?? dev?.defaultLocale ?? 'en' })) ??
|
|
303
|
+
componentState.loadComponents({
|
|
304
|
+
mode: dev?.mode,
|
|
305
|
+
projectId: dev?.projectId ?? window.__PROJECT_ID__,
|
|
306
|
+
locale: realLocale,
|
|
307
|
+
instances: [{ id: instanceId, component: { id: componentId }, properties }],
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
// 如果前置 preload 已经触发过了,直接返回,不再触发下面的 /preload 逻辑
|
|
311
|
+
if (previousRef.current) {
|
|
312
|
+
return previousRef.current;
|
|
308
313
|
}
|
|
309
314
|
return null;
|
|
310
315
|
}
|