@blocklet/pages-kit 0.5.54 → 0.5.56

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,26 +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
- previousRef.current = result;
294
+ // 只缓存 props 以外的数据,props 会跟随语言动态更新
295
+ previousRef.current = omit(result, 'props');
294
296
  return result;
295
297
  }
296
- const isProduction = dev?.mode === 'production';
297
- // 在 production 模式下,如果前置 preload 已经触发过了,直接返回,不再触发下面的 /preload 逻辑
298
- if (isProduction && previousRef.current) {
299
- return previousRef.current;
300
- }
301
298
  if (instanceId) {
302
299
  const key = [instanceId, realLocale].join('-');
303
- COMPONENT_LOADER_MAP[key] ??= customComponentStates()
304
- .getState()
305
- .loadComponents({
306
- mode: dev?.mode,
307
- projectId: dev?.projectId ?? window.__PROJECT_ID__,
308
- locale: realLocale,
309
- instances: [{ id: instanceId, component: { id: componentId }, properties }],
310
- });
311
- if (previousRef.current)
312
- return previousRef.current;
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;
313
313
  }
314
314
  return null;
315
315
  }