@blocklet/pages-kit 0.6.51 → 0.6.52

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.
@@ -53,12 +53,16 @@ function importCustomComponent(m, { componentId }) {
53
53
  if (m && m instanceof Promise) {
54
54
  // handle Promise case
55
55
  return (props) => {
56
- const [loading, setLoading] = (0, react_1.useState)(true);
56
+ const [loading, setLoading] = (0, react_1.useState)(false);
57
57
  const [error, setError] = (0, react_1.useState)(null);
58
58
  const [ResolvedComponent, setResolvedComponent] = (0, react_1.useState)(null);
59
59
  // 只在组件首次加载时执行,避免重复加载
60
60
  (0, react_1.useEffect)(() => {
61
61
  let isMounted = true;
62
+ // 最大 100ms 后显示 loading,避免页面撕裂感
63
+ const loadingTimer = setTimeout(() => {
64
+ setLoading(true);
65
+ }, 100);
62
66
  const loadComponent = async () => {
63
67
  try {
64
68
  const result = await m;
@@ -86,6 +90,7 @@ function importCustomComponent(m, { componentId }) {
86
90
  }
87
91
  finally {
88
92
  if (isMounted) {
93
+ clearTimeout(loadingTimer);
89
94
  setLoading(false);
90
95
  }
91
96
  }
@@ -93,6 +98,7 @@ function importCustomComponent(m, { componentId }) {
93
98
  loadComponent();
94
99
  return () => {
95
100
  isMounted = false;
101
+ clearTimeout(loadingTimer);
96
102
  };
97
103
  }, []); // 仅在组件挂载时执行一次
98
104
  // 使用useMemo缓存渲染内容,避免不必要的重计算
@@ -109,10 +115,10 @@ function importCustomComponent(m, { componentId }) {
109
115
  }
110
116
  return null;
111
117
  }, [loading, error, ResolvedComponent, props]);
112
- return ((0, jsx_runtime_1.jsx)(material_1.Fade, { in: !loading, timeout: 500, children: (0, jsx_runtime_1.jsx)(material_1.Box, { className: "CustomComponent-root", sx: {
113
- // 使用 display: contents 避免外层包裹的 div 样式影响组件内部样式
114
- display: 'contents',
115
- }, children: content }) }));
118
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { className: "CustomComponent-root", id: `CustomComponent-${componentId}`, sx: {
119
+ // 使用 display: contents 避免外层包裹的 div 样式影响组件内部样式
120
+ display: 'contents',
121
+ }, children: content }));
116
122
  };
117
123
  }
118
124
  // non-Promise case