@blocklet/pages-kit 0.5.54 → 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.
@@ -34,6 +34,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
34
34
  const css_1 = require("@emotion/css");
35
35
  const material_1 = require("@mui/material");
36
36
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
37
+ const omit_1 = __importDefault(require("lodash/omit"));
37
38
  const set_1 = __importDefault(require("lodash/set"));
38
39
  const react_1 = require("react");
39
40
  const react_helmet_1 = require("react-helmet");
@@ -323,26 +324,25 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
323
324
  const realLocale = getRealLocale(locale);
324
325
  const result = getComponentByComponentId({ componentId, locale: realLocale, instanceId });
325
326
  if (result) {
326
- previousRef.current = result;
327
+ // 只缓存 props 以外的数据,props 会跟随语言动态更新
328
+ previousRef.current = (0, omit_1.default)(result, 'props');
327
329
  return result;
328
330
  }
329
- const isProduction = dev?.mode === 'production';
330
- // 在 production 模式下,如果前置 preload 已经触发过了,直接返回,不再触发下面的 /preload 逻辑
331
- if (isProduction && previousRef.current) {
332
- return previousRef.current;
333
- }
334
331
  if (instanceId) {
335
332
  const key = [instanceId, realLocale].join('-');
336
- COMPONENT_LOADER_MAP[key] ??= (0, exports.customComponentStates)()
337
- .getState()
338
- .loadComponents({
339
- mode: dev?.mode,
340
- projectId: dev?.projectId ?? window.__PROJECT_ID__,
341
- locale: realLocale,
342
- instances: [{ id: instanceId, component: { id: componentId }, properties }],
343
- });
344
- if (previousRef.current)
345
- return previousRef.current;
333
+ const componentState = (0, exports.customComponentStates)().getState();
334
+ COMPONENT_LOADER_MAP[key] ??=
335
+ Promise.resolve(componentState.getComponent({ componentId, locale: realLocale ?? dev?.defaultLocale ?? 'en' })) ??
336
+ componentState.loadComponents({
337
+ mode: dev?.mode,
338
+ projectId: dev?.projectId ?? window.__PROJECT_ID__,
339
+ locale: realLocale,
340
+ instances: [{ id: instanceId, component: { id: componentId }, properties }],
341
+ });
342
+ }
343
+ // 如果前置 preload 已经触发过了,直接返回,不再触发下面的 /preload 逻辑
344
+ if (previousRef.current) {
345
+ return previousRef.current;
346
346
  }
347
347
  return null;
348
348
  }