@blocklet/pages-kit 0.6.50 → 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.
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cx } from '@emotion/css';
3
- import { Skeleton, Fade, Box } from '@mui/material';
3
+ import { Skeleton, Box } from '@mui/material';
4
4
  import isEmpty from 'lodash/isEmpty';
5
5
  import omit from 'lodash/omit';
6
6
  import set from 'lodash/set';
@@ -21,12 +21,16 @@ function importCustomComponent(m, { componentId }) {
21
21
  if (m && m instanceof Promise) {
22
22
  // handle Promise case
23
23
  return (props) => {
24
- const [loading, setLoading] = useState(true);
24
+ const [loading, setLoading] = useState(false);
25
25
  const [error, setError] = useState(null);
26
26
  const [ResolvedComponent, setResolvedComponent] = useState(null);
27
27
  // 只在组件首次加载时执行,避免重复加载
28
28
  useEffect(() => {
29
29
  let isMounted = true;
30
+ // 最大 100ms 后显示 loading,避免页面撕裂感
31
+ const loadingTimer = setTimeout(() => {
32
+ setLoading(true);
33
+ }, 100);
30
34
  const loadComponent = async () => {
31
35
  try {
32
36
  const result = await m;
@@ -54,6 +58,7 @@ function importCustomComponent(m, { componentId }) {
54
58
  }
55
59
  finally {
56
60
  if (isMounted) {
61
+ clearTimeout(loadingTimer);
57
62
  setLoading(false);
58
63
  }
59
64
  }
@@ -61,6 +66,7 @@ function importCustomComponent(m, { componentId }) {
61
66
  loadComponent();
62
67
  return () => {
63
68
  isMounted = false;
69
+ clearTimeout(loadingTimer);
64
70
  };
65
71
  }, []); // 仅在组件挂载时执行一次
66
72
  // 使用useMemo缓存渲染内容,避免不必要的重计算
@@ -77,10 +83,10 @@ function importCustomComponent(m, { componentId }) {
77
83
  }
78
84
  return null;
79
85
  }, [loading, error, ResolvedComponent, props]);
80
- return (_jsx(Fade, { in: !loading, timeout: 500, children: _jsx(Box, { className: "CustomComponent-root", sx: {
81
- // 使用 display: contents 避免外层包裹的 div 样式影响组件内部样式
82
- display: 'contents',
83
- }, children: content }) }));
86
+ return (_jsx(Box, { className: "CustomComponent-root", id: `CustomComponent-${componentId}`, sx: {
87
+ // 使用 display: contents 避免外层包裹的 div 样式影响组件内部样式
88
+ display: 'contents',
89
+ }, children: content }));
84
90
  };
85
91
  }
86
92
  // non-Promise case