From c7fef4f07de7ec918fff55216dff03d5a3332f3d Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 4 May 2024 17:37:12 +0200 Subject: [PATCH 1/2] [data grid] Reduce bundle size with error messages --- .../src/DataGridPremium/DataGridPremium.tsx | 4 +++- .../src/DataGridPro/DataGridPro.tsx | 4 +++- packages/x-data-grid/src/DataGrid/DataGrid.tsx | 5 +++-- .../src/internals/utils/propValidation.ts | 15 ++++++--------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx index 2528ab754e58b..ec1f307d37e32 100644 --- a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx +++ b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx @@ -42,7 +42,9 @@ const DataGridPremiumRaw = React.forwardRef(function DataGridPremium [] = [ ]; const warnedOnceCache = new Set(); -const warnOnce = (message: string) => { +function warnOnce(message: string) { if (!warnedOnceCache.has(message)) { console.error(message); warnedOnceCache.add(message); } -}; +} -export const validateProps = (props: TProps, validators: PropValidator[]) => { - if (process.env.NODE_ENV === 'production') { - return; - } +export function validateProps(props: TProps, validators: PropValidator[]) { validators.forEach((validator) => { const warning = validator(props); if (warning) { warnOnce(warning); } }); -}; +} -export const clearWarningsCache = () => { +export function clearWarningsCache() { warnedOnceCache.clear(); -}; +} From 74a532a7470e4c3eb9fa4d33837e17a2ec87187f Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 4 May 2024 18:18:35 +0200 Subject: [PATCH 2/2] it's not enough, need this as well --- .../src/DataGridPremium/DataGridPremium.tsx | 9 +++--- .../x-data-grid/src/DataGrid/DataGrid.tsx | 32 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx index ec1f307d37e32..33c17ae307f2f 100644 --- a/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx +++ b/packages/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx @@ -28,10 +28,11 @@ export type { GridPremiumSlotsComponent as GridSlots } from '../models'; const releaseInfo = getReleaseInfo(); -const dataGridPremiumPropValidators: PropValidator[] = [ - ...propValidatorsDataGrid, - ...propValidatorsDataGridPro, -]; +let dataGridPremiumPropValidators: PropValidator[]; + +if (process.env.NODE_ENV !== 'production') { + dataGridPremiumPropValidators = [...propValidatorsDataGrid, ...propValidatorsDataGridPro]; +} const DataGridPremiumRaw = React.forwardRef(function DataGridPremium( inProps: DataGridPremiumProps, diff --git a/packages/x-data-grid/src/DataGrid/DataGrid.tsx b/packages/x-data-grid/src/DataGrid/DataGrid.tsx index 54726280f7e87..1ba6770356acf 100644 --- a/packages/x-data-grid/src/DataGrid/DataGrid.tsx +++ b/packages/x-data-grid/src/DataGrid/DataGrid.tsx @@ -15,20 +15,24 @@ import { export type { GridSlotsComponent as GridSlots } from '../models'; -const propValidators: PropValidator[] = [ - ...propValidatorsDataGrid, - // Only validate in MIT version - (props) => - (props.columns && - props.columns.some((column) => column.resizable) && - [ - `MUI X: \`column.resizable = true\` is not a valid prop.`, - 'Column resizing is not available in the MIT version.', - '', - 'You need to upgrade to DataGridPro or DataGridPremium component to unlock this feature.', - ].join('\n')) || - undefined, -]; +let propValidators: PropValidator[]; + +if (process.env.NODE_ENV !== 'production') { + propValidators = [ + ...propValidatorsDataGrid, + // Only validate in MIT version + (props) => + (props.columns && + props.columns.some((column) => column.resizable) && + [ + `MUI X: \`column.resizable = true\` is not a valid prop.`, + 'Column resizing is not available in the MIT version.', + '', + 'You need to upgrade to DataGridPro or DataGridPremium component to unlock this feature.', + ].join('\n')) || + undefined, + ]; +} const DataGridRaw = React.forwardRef(function DataGrid( inProps: DataGridProps,