[data grid] Restrict warning messages to non-production environments in various components#22461
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
Pull request overview
This PR reduces production code paths in Data Grid packages by gating development warning messages behind process.env.NODE_ENV !== 'production' checks.
Changes:
- Adds production guards around
warnOncecalls in community, Pro, and Premium-related Data Grid code paths. - Covers validation, sorting/filtering sanitization, export warnings, editing/data source error hints, list view, actions cell, tree data, and row reorder warnings.
- Keeps most functional behavior unchanged, but one filtering sanitizer path now needs correction.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/x-data-grid/src/internals/utils/propValidation.ts |
Skips prop validation warnings in production. |
packages/x-data-grid/src/hooks/utils/useGridSelector.ts |
Gates selector initialization warning. |
packages/x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts |
Gates multi-sort warning while preserving sort model sanitization. |
packages/x-data-grid/src/hooks/features/listView/useGridListView.tsx |
Gates missing list view column warning. |
packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts |
Gates filter model warnings, but changes production sanitization behavior. |
packages/x-data-grid/src/hooks/features/export/serializers/csvSerializer.ts |
Gates CSV object-value export warning. |
packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts |
Gates missing row update error handler warning. |
packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts |
Gates missing cell update error handler warning. |
packages/x-data-grid/src/hooks/features/dataSource/useGridDataSourceBase.ts |
Gates missing data source error handler warnings. |
packages/x-data-grid/src/components/cell/GridActionsCell.tsx |
Gates invalid actions cell child warning. |
packages/x-data-grid-pro/src/hooks/features/treeData/utils.ts |
Gates missing setTreeDataPath warning. |
packages/x-data-grid-pro/src/hooks/features/rowReorder/utils.ts |
Gates row reorder process update error warning. |
packages/x-data-grid-pro/src/hooks/features/rowReorder/reorderExecutor.ts |
Gates no-op row reorder warning. |
packages/x-data-grid-pro/src/hooks/features/dataSource/useGridDataSourceBasePro.ts |
Gates Pro data source error handler warning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| let items: GridFilterItem[]; | ||
| if (hasSeveralItems && disableMultipleColumnsFiltering) { | ||
| if (hasSeveralItems && disableMultipleColumnsFiltering && process.env.NODE_ENV !== 'production') { |
| String(cellParams.formattedValue) === '[object Object]' && | ||
| process.env.NODE_ENV !== 'production' |
Can you merge PR, I'm not able to do it |
…in various components (mui#22461) Co-authored-by: Michel Engelen <[email protected]>
| const hasItemWithoutOperator = items.some((item) => item.operator == null); | ||
|
|
||
| if (hasItemsWithoutIds) { | ||
| if (hasItemsWithoutIds && process.env.NODE_ENV !== 'production') { |
There was a problem hiding this comment.
How about we update this to not combine the branches in the code for process.env.NODE_ENV !== 'production'? The code pattern is supposed to be an if process.env.NODE_ENV !== 'production' at the top branch and then whatever logic makes sense. At least, I believe it's what the rest of the codebase follows. The idea was to make it easier during review to identify branches that are non prod only
| if (hasItemsWithoutIds && process.env.NODE_ENV !== 'production') { | |
| if (process.env.NODE_ENV !== 'production') { | |
| if (hasItemsWithoutIds) { |
There was a problem hiding this comment.
you could even argue to put this at the very top of the function... But there are only 2 occasions (3 if you restructure a bit) where this would apply:
--- a/packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts
+++ b/packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts
@@ -86,7 +86,16 @@ export const sanitizeFilterModel = (
let items: GridFilterItem[];
if (hasSeveralItems && disableMultipleColumnsFiltering) {
- if (process.env.NODE_ENV !== 'production') {
+ items = [model.items[0]];
+ } else {
+ items = model.items;
+ }
+
+ const hasItemsWithoutIds = hasSeveralItems && items.some((item) => item.id == null);
+ const hasItemWithoutOperator = items.some((item) => item.operator == null);
+
+ if (process.env.NODE_ENV !== 'production') {
+ if (hasSeveralItems && disableMultipleColumnsFiltering) {
warnOnce(
[
'MUI X: The `filterModel` can only contain a single item when the `disableMultipleColumnsFiltering` prop is set to `true`.',
@@ -95,26 +104,20 @@ export const sanitizeFilterModel = (
'error',
);
}
- items = [model.items[0]];
- } else {
- items = model.items;
- }
-
- const hasItemsWithoutIds = hasSeveralItems && items.some((item) => item.id == null);
- const hasItemWithoutOperator = items.some((item) => item.operator == null);
- if (hasItemsWithoutIds && process.env.NODE_ENV !== 'production') {
- warnOnce(
- 'MUI X: The `id` field is required on `filterModel.items` when you use multiple filters.',
- 'error',
- );
- }
+ if (hasItemsWithoutIds) {
+ warnOnce(
+ 'MUI X: The `id` field is required on `filterModel.items` when you use multiple filters.',
+ 'error',
+ );
+ }
- if (hasItemWithoutOperator && process.env.NODE_ENV !== 'production') {
- warnOnce(
- 'MUI X: The `operator` field is required on `filterModel.items`, one or more of your filtering item has no `operator` provided.',
- 'error',
- );
+ if (hasItemWithoutOperator) {
+ warnOnce(
+ 'MUI X: The `operator` field is required on `filterModel.items`, one or more of your filtering item has no `operator` provided.',
+ 'error',
+ );
+ }
}
if (hasItemWithoutOperator || hasItemsWithoutIds) {
Summary
Reduce production bundle size in
@mui/x-data-grid*by gating dev-onlywarnOncecalls behindprocess.env.NODE_ENV !== 'production'checks. Brings 7 ungated dev hints in line with the existing convention already used elsewhere in these packages.Existing convention in master
This pattern is already established in
x-data-grid*packages, this PR brings ungated outliers in line with it.Examples already gated on master:
x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts:185} else if (process.env.NODE_ENV !== 'production') { warnOnce(...) }x-data-grid-premium/src/hooks/features/export/serializer/excelSerializer.ts:156, 202if (process.env.NODE_ENV !== 'production') { ... warnOnce([...]) }Gates added in this PR
1
x-data-grid/src/hooks/features/listView/useGridListView.tsx:79warnOnce"listViewColumn must be set when listView is enabled"&& process.env.NODE_ENV !== 'production'in if condition2
x-data-grid/src/hooks/utils/useGridSelector.ts:62warnOnce"selector called before state initialization"&& process.env.NODE_ENV !== 'production'in if condition3
x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts:28warnOnce"multi-column sort when disableMultipleColumnsSorting is true"if (process.env.NODE_ENV !== 'production')(return-from-sanitizestays unconditional)4
x-data-grid/src/internals/utils/propValidation.ts:48warnOnce(loop)forEachloop in prod5
x-data-grid-pro/src/hooks/features/treeData/utils.ts:34warnOnce(whole fn body)"requires setTreeDataPath() prop"6
x-data-grid-pro/src/hooks/features/rowReorder/reorderExecutor.ts:49warnOnce"API call resulted in a no-op"7
x-data-grid-pro/src/hooks/features/rowReorder/utils.ts:239warnOnce(in else)"missing onProcessRowUpdateError() handler"else if (process.env.NODE_ENV !== 'production')