Compare commits

..

1 Commits

Author SHA1 Message Date
Yunus M
3454e2956b chore: implement vendor chunk splitting for production builds
Add strategic code splitting to reduce main bundle size from 11MB to 3.7MB
(66% reduction) and improve browser caching efficiency.

Changes:
- Add splitChunks configuration with vendor cache groups:
  * vendors-react: React, Redux, Router (~168KB)
  * vendors-antd: Ant Design core (~1.6MB)
  * vendors-antd-icons: Ant Design icons (~150KB)
  * vendors-charts: Chart libraries (~264KB)
  * vendors-react-query: React Query (~47KB)
  * vendors-signozhq: SigNoz UI components (~338KB)
  * vendors-utilities: lodash-es, dnd-kit, dayjs, axios, i18next (~198KB)
  * vendors-monaco: Monaco editor (~11KB)
  * vendors-common: Other shared dependencies (~1.2MB)
- Enable module concatenation for better tree-shaking
- Update bundlesize.config.json with granular limits per chunk type
- Restrict window.store exposure to development only

Performance Impact:
- Main bundle: 11MB → 3.7MB (66% reduction)
- Total build: 250MB → 97MB (61% reduction)
- Better browser caching (vendor chunks change less frequently)
- Faster subsequent page loads (cached vendor chunks)

Breaking Changes: None
Migration: None required
2026-02-16 21:03:29 +05:30
12 changed files with 160 additions and 161 deletions

View File

@@ -1,8 +1,52 @@
{
"files": [
{
"path": "./build/**.js",
"maxSize": "1.2MB"
"path": "./build/runtime~*.js",
"maxSize": "50KB"
},
{
"path": "./build/vendors-react.*.js",
"maxSize": "300KB"
},
{
"path": "./build/vendors-antd.*.js",
"maxSize": "1MB"
},
{
"path": "./build/vendors-antd-icons.*.js",
"maxSize": "2.5MB"
},
{
"path": "./build/vendors-charts.*.js",
"maxSize": "400KB"
},
{
"path": "./build/vendors-react-query.*.js",
"maxSize": "100KB"
},
{
"path": "./build/vendors-utilities.*.js",
"maxSize": "600KB"
},
{
"path": "./build/vendors-monaco.*.js",
"maxSize": "3MB"
},
{
"path": "./build/vendors-common.*.js",
"maxSize": "800KB"
},
{
"path": "./build/main.*.js",
"maxSize": "500KB"
},
{
"path": "./build/Home.*.js",
"maxSize": "300KB"
},
{
"path": "./build/*.js",
"maxSize": "1MB"
}
]
}

View File

@@ -1,7 +1,6 @@
.overview-content {
display: flex;
flex-direction: column;
gap: 16px;
.overview-settings {
border-radius: 3px;
@@ -56,35 +55,6 @@
border: 1px solid var(--bg-slate-400);
background: var(--bg-ink-300);
}
.cross-panel-sync-section {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
flex-wrap: wrap;
.cross-panel-sync-info {
display: flex;
flex-direction: column;
flex: 1;
min-width: 200px;
.cross-panel-sync-title {
color: var(--bg-vanilla-400);
font-size: 14px;
}
.cross-panel-sync-description {
color: var(--bg-vanilla-400);
font-size: 12px;
}
}
.ant-radio-group {
flex-shrink: 0;
}
}
}
.overview-settings-footer {
@@ -198,15 +168,6 @@
border: 1px solid var(--bg-vanilla-300);
background: var(--bg-vanilla-300);
}
.cross-panel-sync-section {
.cross-panel-sync-title {
color: var(--bg-ink-400);
}
.cross-panel-sync-description {
color: var(--bg-ink-300);
}
}
}
.overview-settings-footer {

View File

@@ -1,15 +1,11 @@
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Col, Input, Radio, Select, Space, Typography } from 'antd';
import { Col, Input, Select, Space, Typography } from 'antd';
import AddTags from 'container/DashboardContainer/DashboardSettings/General/AddTags';
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
import { isEqual } from 'lodash-es';
import { Check, X } from 'lucide-react';
import { useDashboard } from 'providers/Dashboard/Dashboard';
import {
CROSS_PANEL_SYNC_OPTIONS,
CrossPanelSync,
} from 'types/api/dashboard/getAll';
import { Button } from './styles';
import { Base64Icons } from './utils';
@@ -25,13 +21,8 @@ function GeneralDashboardSettings(): JSX.Element {
const selectedData = selectedDashboard?.data;
const {
title = '',
tags = [],
description = '',
image = Base64Icons[0],
crossPanelSync = 'NONE',
} = selectedData || {};
const { title = '', tags = [], description = '', image = Base64Icons[0] } =
selectedData || {};
const [updatedTitle, setUpdatedTitle] = useState<string>(title);
const [updatedTags, setUpdatedTags] = useState<string[]>(tags || []);
@@ -39,10 +30,6 @@ function GeneralDashboardSettings(): JSX.Element {
description || '',
);
const [updatedImage, setUpdatedImage] = useState<string>(image);
const [
updatedCrossPanelSync,
setUpdatedCrossPanelSync,
] = useState<CrossPanelSync>(crossPanelSync);
const [numberOfUnsavedChanges, setNumberOfUnsavedChanges] = useState<number>(
0,
);
@@ -63,7 +50,6 @@ function GeneralDashboardSettings(): JSX.Element {
tags: updatedTags,
title: updatedTitle,
image: updatedImage,
crossPanelSync: updatedCrossPanelSync,
},
},
{
@@ -79,13 +65,12 @@ function GeneralDashboardSettings(): JSX.Element {
useEffect(() => {
let numberOfUnsavedChanges = 0;
const initialValues = [title, description, tags, image, crossPanelSync];
const initialValues = [title, description, tags, image];
const updatedValues = [
updatedTitle,
updatedDescription,
updatedTags,
updatedImage,
updatedCrossPanelSync,
];
initialValues.forEach((val, index) => {
if (!isEqual(val, updatedValues[index])) {
@@ -94,38 +79,21 @@ function GeneralDashboardSettings(): JSX.Element {
});
setNumberOfUnsavedChanges(numberOfUnsavedChanges);
}, [
crossPanelSync,
description,
image,
tags,
title,
updatedCrossPanelSync,
updatedDescription,
updatedImage,
updatedTags,
updatedTitle,
]);
const crossPanelSyncOptions = useMemo(() => {
return CROSS_PANEL_SYNC_OPTIONS.map((value) => {
const sanitizedValue = value.toLowerCase();
const label =
sanitizedValue === 'none'
? 'No Sync'
: sanitizedValue.charAt(0).toUpperCase() + sanitizedValue.slice(1);
return {
label,
value,
};
});
}, []);
const discardHandler = (): void => {
setUpdatedTitle(title);
setUpdatedImage(image);
setUpdatedTags(tags);
setUpdatedDescription(description);
setUpdatedCrossPanelSync(crossPanelSync);
};
return (
@@ -188,28 +156,6 @@ function GeneralDashboardSettings(): JSX.Element {
</div>
</Space>
</Col>
<Col className="overview-settings">
<div className="cross-panel-sync-section">
<div className="cross-panel-sync-info">
<Typography className="cross-panel-sync-title">
Cross-Panel Sync
</Typography>
<Typography.Text className="cross-panel-sync-description">
Sync crosshair and tooltip across all the dashboard panels
</Typography.Text>
</div>
<Radio.Group
value={updatedCrossPanelSync}
onChange={(e): void =>
setUpdatedCrossPanelSync(e.target.value as CrossPanelSync)
}
optionType="button"
buttonStyle="solid"
options={crossPanelSyncOptions}
data-testid="cross-panel-sync"
/>
</div>
</Col>
{numberOfUnsavedChanges > 0 && (
<div className="overview-settings-footer">
<div className="unsaved">

View File

@@ -1,7 +1,7 @@
import { PrecisionOption } from 'components/Graph/types';
import { LegendConfig, TooltipRenderArgs } from 'lib/uPlotV2/components/types';
import { UPlotConfigBuilder } from 'lib/uPlotV2/config/UPlotConfigBuilder';
import { CrossPanelSync } from 'types/api/dashboard/getAll';
import { DashboardCursorSync } from 'lib/uPlotV2/plugins/TooltipPlugin/types';
interface BaseChartProps {
width: number;
@@ -17,7 +17,7 @@ interface BaseChartProps {
interface UPlotBasedChartProps {
config: UPlotConfigBuilder;
data: uPlot.AlignedData;
syncMode?: CrossPanelSync;
syncMode?: DashboardCursorSync;
syncKey?: string;
plotRef?: (plot: uPlot | null) => void;
onDestroy?: (plot: uPlot) => void;

View File

@@ -13,7 +13,6 @@ import { getTimeRange } from 'utils/getTimeRange';
import BarChart from '../../charts/BarChart/BarChart';
import ChartManager from '../../components/ChartManager/ChartManager';
import { usePanelContextMenu } from '../../hooks/usePanelContextMenu';
import { PanelMode } from '../types';
import { prepareBarPanelConfig, prepareBarPanelData } from './utils';
import '../Panel.styles.scss';
@@ -28,11 +27,7 @@ function BarPanel(props: PanelWrapperProps): JSX.Element {
onToggleModelHandler,
} = props;
const uPlotRef = useRef<uPlot | null>(null);
const {
toScrollWidgetId,
setToScrollWidgetId,
selectedDashboard,
} = useDashboard();
const { toScrollWidgetId, setToScrollWidgetId } = useDashboard();
const graphRef = useRef<HTMLDivElement>(null);
const [minTimeScale, setMinTimeScale] = useState<number>();
const [maxTimeScale, setMaxTimeScale] = useState<number>();
@@ -122,15 +117,6 @@ function BarPanel(props: PanelWrapperProps): JSX.Element {
onToggleModelHandler,
]);
const crossPanelSync = selectedDashboard?.data?.crossPanelSync ?? 'NONE';
const cursorSyncMode = useMemo(() => {
if (panelMode !== PanelMode.DASHBOARD_VIEW) {
return 'NONE';
}
return crossPanelSync;
}, [panelMode, crossPanelSync]);
const onPlotDestroy = useCallback(() => {
uPlotRef.current = null;
}, []);
@@ -151,7 +137,6 @@ function BarPanel(props: PanelWrapperProps): JSX.Element {
onDestroy={onPlotDestroy}
yAxisUnit={widget.yAxisUnit}
decimalPrecision={widget.decimalPrecision}
syncMode={cursorSyncMode}
timezone={timezone.value}
data={chartData as uPlot.AlignedData}
width={containerDimensions.width}

View File

@@ -14,7 +14,6 @@ import uPlot from 'uplot';
import { getTimeRange } from 'utils/getTimeRange';
import { prepareChartData, prepareUPlotConfig } from '../TimeSeriesPanel/utils';
import { PanelMode } from '../types';
import '../Panel.styles.scss';
@@ -27,11 +26,7 @@ function TimeSeriesPanel(props: PanelWrapperProps): JSX.Element {
isFullViewMode,
onToggleModelHandler,
} = props;
const {
toScrollWidgetId,
setToScrollWidgetId,
selectedDashboard,
} = useDashboard();
const { toScrollWidgetId, setToScrollWidgetId } = useDashboard();
const graphRef = useRef<HTMLDivElement>(null);
const [minTimeScale, setMinTimeScale] = useState<number>();
const [maxTimeScale, setMaxTimeScale] = useState<number>();
@@ -101,15 +96,6 @@ function TimeSeriesPanel(props: PanelWrapperProps): JSX.Element {
timezone,
]);
const crossPanelSync = selectedDashboard?.data?.crossPanelSync ?? 'NONE';
const cursorSyncMode = useMemo(() => {
if (panelMode !== PanelMode.DASHBOARD_VIEW) {
return 'NONE';
}
return crossPanelSync;
}, [panelMode, crossPanelSync]);
const layoutChildren = useMemo(() => {
if (!isFullViewMode) {
return null;
@@ -140,7 +126,6 @@ function TimeSeriesPanel(props: PanelWrapperProps): JSX.Element {
}}
yAxisUnit={widget.yAxisUnit}
decimalPrecision={widget.decimalPrecision}
syncMode={cursorSyncMode}
timezone={timezone.value}
data={chartData as uPlot.AlignedData}
width={containerDimensions.width}

View File

@@ -13,6 +13,7 @@ import {
updateWindowSize,
} from './tooltipController';
import {
DashboardCursorSync,
TooltipControllerContext,
TooltipControllerState,
TooltipLayoutInfo,
@@ -34,7 +35,7 @@ export default function TooltipPlugin({
render,
maxWidth = 300,
maxHeight = 400,
syncMode = 'NONE',
syncMode = DashboardCursorSync.None,
syncKey = '_tooltip_sync_global_',
canPinTooltip = false,
}: TooltipPluginProps): JSX.Element | null {
@@ -77,11 +78,11 @@ export default function TooltipPlugin({
// render on every mouse move.
const controller: TooltipControllerState = createInitialControllerState();
const syncTooltipWithDashboard = syncMode === 'TOOLTIP';
const syncTooltipWithDashboard = syncMode === DashboardCursorSync.Tooltip;
// Enable uPlot's built-in cursor sync when requested so that
// crosshair / tooltip can follow the dashboard-wide cursor.
if (syncMode !== 'NONE' && config.scales[0]?.props.time) {
if (syncMode !== DashboardCursorSync.None && config.scales[0]?.props.time) {
config.setCursor({
sync: { key: syncKey, scales: ['x', null] },
});

View File

@@ -4,7 +4,6 @@ import type {
ReactNode,
RefObject,
} from 'react';
import { CrossPanelSync } from 'types/api/dashboard/getAll';
import type uPlot from 'uplot';
import type { TooltipRenderArgs } from '../../components/types';
@@ -12,6 +11,12 @@ import type { UPlotConfigBuilder } from '../../config/UPlotConfigBuilder';
export const TOOLTIP_OFFSET = 10;
export enum DashboardCursorSync {
Crosshair,
None,
Tooltip,
}
export interface TooltipViewState {
plot?: uPlot | null;
style: Partial<CSSProperties>;
@@ -30,7 +35,7 @@ export interface TooltipLayoutInfo {
export interface TooltipPluginProps {
config: UPlotConfigBuilder;
canPinTooltip?: boolean;
syncMode?: CrossPanelSync;
syncMode?: DashboardCursorSync;
syncKey?: string;
render: (args: TooltipRenderArgs) => ReactNode;
maxWidth?: number;
@@ -81,7 +86,7 @@ export interface TooltipControllerContext {
rafId: MutableRefObject<number | null>;
updateState: (updates: Partial<TooltipViewState>) => void;
renderRef: MutableRefObject<(args: TooltipRenderArgs) => ReactNode>;
syncMode: CrossPanelSync;
syncMode: DashboardCursorSync;
syncKey: string;
canPinTooltip: boolean;
createTooltipContents: () => React.ReactNode;

View File

@@ -7,6 +7,7 @@ import type uPlot from 'uplot';
import { TooltipRenderArgs } from '../../components/types';
import { UPlotConfigBuilder } from '../../config/UPlotConfigBuilder';
import TooltipPlugin from '../TooltipPlugin/TooltipPlugin';
import { DashboardCursorSync } from '../TooltipPlugin/types';
// ---------------------------------------------------------------------------
// Mock helpers
@@ -99,7 +100,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: renderFn,
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
...extraProps,
}),
);
@@ -126,7 +127,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => React.createElement('div', null, 'tooltip-body'),
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
}),
);
@@ -140,7 +141,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => null,
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
}),
);
@@ -216,7 +217,7 @@ describe('TooltipPlugin', () => {
{ type: 'button', onClick: args.dismiss },
'Dismiss',
),
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
canPinTooltip: true,
}),
);
@@ -260,7 +261,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config: config,
render: () => React.createElement('div', null, 'tooltip-body'),
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
canPinTooltip: true,
}),
);
@@ -304,7 +305,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => React.createElement('div', null, 'pinned content'),
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
canPinTooltip: true,
}),
);
@@ -347,7 +348,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => React.createElement('div', null, 'pinned content'),
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
canPinTooltip: true,
}),
);
@@ -397,7 +398,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => null,
syncMode: 'TOOLTIP',
syncMode: DashboardCursorSync.Tooltip,
syncKey: 'dashboard-sync',
}),
);
@@ -416,7 +417,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => null,
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
}),
);
@@ -432,7 +433,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => null,
syncMode: 'TOOLTIP',
syncMode: DashboardCursorSync.Tooltip,
}),
);
@@ -452,7 +453,7 @@ describe('TooltipPlugin', () => {
React.createElement(TooltipPlugin, {
config,
render: () => null,
syncMode: 'NONE',
syncMode: DashboardCursorSync.None,
}),
);

View File

@@ -20,7 +20,7 @@ const store = createStore(
export type AppDispatch = typeof store.dispatch;
if (window !== undefined) {
if (window !== undefined && process.env.NODE_ENV === 'development') {
window.store = store;
}

View File

@@ -81,13 +81,6 @@ export interface DashboardTemplate {
previewImage: string;
}
export const CROSS_PANEL_SYNC_OPTIONS = [
'NONE',
'CROSSHAIR',
'TOOLTIP',
] as const;
export type CrossPanelSync = typeof CROSS_PANEL_SYNC_OPTIONS[number];
export interface DashboardData {
// uuid?: string;
description?: string;
@@ -100,7 +93,6 @@ export interface DashboardData {
variables: Record<string, IDashboardVariable>;
version?: string;
image?: string;
crossPanelSync?: CrossPanelSync;
}
export interface WidgetRow {

View File

@@ -171,7 +171,7 @@ const config = {
plugins,
optimization: {
chunkIds: 'named',
concatenateModules: false,
concatenateModules: true, // Enable module concatenation for better tree-shaking and smaller bundles
emitOnErrors: true,
flagIncludedChunks: true,
innerGraph: true, // tells webpack whether to conduct inner graph analysis for unused exports.
@@ -182,6 +182,85 @@ const config = {
runtimeChunk: {
name: (entrypoint) => `runtime~${entrypoint.name}`,
},
splitChunks: {
chunks: 'all',
maxInitialRequests: 30,
minSize: 20000,
cacheGroups: {
// Vendor libraries - React, React-DOM, Redux, Router
vendor: {
test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom|react-redux|redux|@reduxjs)[\\/]/,
name: 'vendors-react',
priority: 30,
reuseExistingChunk: true,
enforce: true,
},
// Ant Design icons (separate from core - icons are huge)
antdIcons: {
test: /[\\/]node_modules[\\/](@ant-design\/icons)[\\/]/,
name: 'vendors-antd-icons',
priority: 25,
reuseExistingChunk: true,
enforce: true,
},
// Ant Design core (without icons) - matches antd and @ant-design but not @ant-design/icons
antd: {
test: /[\\/]node_modules[\\/](antd|@ant-design(?!\/icons))[\\/]/,
name: 'vendors-antd',
priority: 20,
reuseExistingChunk: true,
enforce: true,
},
// SigNoz UI components
signozhq: {
test: /[\\/]node_modules[\\/](@signozhq)[\\/]/,
name: 'vendors-signozhq',
priority: 19,
reuseExistingChunk: true,
enforce: true,
},
// Chart libraries
charts: {
test: /[\\/]node_modules[\\/](uplot|chart\.js|@visx|@tanstack\/react-table|@tanstack\/react-virtual)[\\/]/,
name: 'vendors-charts',
priority: 18,
reuseExistingChunk: true,
enforce: true,
},
// React Query
reactQuery: {
test: /[\\/]node_modules[\\/](react-query|@tanstack\/react-query)[\\/]/,
name: 'vendors-react-query',
priority: 17,
reuseExistingChunk: true,
enforce: true,
},
// Large utility libraries
utilities: {
test: /[\\/]node_modules[\\/](lodash-es|@dnd-kit|dayjs|axios|i18next)[\\/]/,
name: 'vendors-utilities',
priority: 15,
reuseExistingChunk: true,
enforce: true,
},
// Monaco editor (very large)
monaco: {
test: /[\\/]node_modules[\\/](@monaco-editor|monaco-editor)[\\/]/,
name: 'vendors-monaco',
priority: 16,
reuseExistingChunk: true,
enforce: true,
},
// Other vendor libraries
common: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors-common',
priority: 10,
minChunks: 2,
reuseExistingChunk: true,
},
},
},
minimizer: [
new TerserPlugin({
parallel: true,