️ perf: Defer Visactor chart libs to dashboard; minimize home bundle

Home started loading `/assets/visactor-*.js` due to static imports of `@visactor/react-vchart` and the Semi theme in dashboard components/hooks. This change moves chart dependencies to lazy/dynamic imports so they load only on dashboard routes.

Changes
- StatsCards.jsx: replace static `VChart` import with `React.lazy` + `Suspense` (fallback: null)
- ChartsPanel.jsx: replace static `VChart` import with `React.lazy` + `Suspense` (fallback: null)
- useDashboardCharts.js: remove static `initVChartSemiTheme` import; dynamically import and initialize the theme inside `useEffect` with a cancel guard

Behavior
- Home page no longer downloads `visactor` chunks on first load
- Chart libraries are fetched only when visiting `/console` (dashboard)
- No functional changes to chart rendering

Files
- web/src/components/dashboard/StatsCards.jsx
- web/src/components/dashboard/ChartsPanel.jsx
- web/src/hooks/dashboard/useDashboardCharts.js

Verification
- Build the app (`npm run build`) and open `/`: no `/assets/visactor-*.js` requests
- Navigate to `/console`: `visactor` chunks load and charts render as expected

Breaking Changes
- None

Follow-ups
- If needed, further trim homepage bundle by reducing heavy icon sets on the hero section
This commit is contained in:
t0ng7u
2025-08-17 01:22:44 +08:00
parent 9805d35a5d
commit b67a42e0a8
6 changed files with 60 additions and 46 deletions

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import React, { Suspense } from 'react';
import { Card, Tabs, TabPane } from '@douyinfe/semi-ui';
import { PieChart } from 'lucide-react';
import {
@@ -25,7 +25,9 @@ import {
IconPulse,
IconPieChart2Stroked
} from '@douyinfe/semi-icons';
import { VChart } from '@visactor/react-vchart';
const LazyVChart = React.lazy(() =>
import('@visactor/react-vchart').then(m => ({ default: m.VChart }))
);
const ChartsPanel = ({
activeChartTab,
@@ -86,28 +88,36 @@ const ChartsPanel = ({
>
<div className="h-96 p-2">
{activeChartTab === '1' && (
<VChart
spec={spec_line}
option={CHART_CONFIG}
/>
<Suspense fallback={null}>
<LazyVChart
spec={spec_line}
option={CHART_CONFIG}
/>
</Suspense>
)}
{activeChartTab === '2' && (
<VChart
spec={spec_model_line}
option={CHART_CONFIG}
/>
<Suspense fallback={null}>
<LazyVChart
spec={spec_model_line}
option={CHART_CONFIG}
/>
</Suspense>
)}
{activeChartTab === '3' && (
<VChart
spec={spec_pie}
option={CHART_CONFIG}
/>
<Suspense fallback={null}>
<LazyVChart
spec={spec_pie}
option={CHART_CONFIG}
/>
</Suspense>
)}
{activeChartTab === '4' && (
<VChart
spec={spec_rank_bar}
option={CHART_CONFIG}
/>
<Suspense fallback={null}>
<LazyVChart
spec={spec_rank_bar}
option={CHART_CONFIG}
/>
</Suspense>
)}
</div>
</Card>