Skip to content

[data grid] Restrict warning messages to non-production environments in various components#22461

Merged
michelengelen merged 5 commits into
mui:masterfrom
sai6855:grid-gate
Jun 9, 2026
Merged

[data grid] Restrict warning messages to non-production environments in various components#22461
michelengelen merged 5 commits into
mui:masterfrom
sai6855:grid-gate

Conversation

@sai6855

@sai6855 sai6855 commented May 15, 2026

Copy link
Copy Markdown
Member

Summary

Reduce production bundle size in @mui/x-data-grid* by gating dev-only warnOnce calls behind process.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:

File:line Pattern
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, 202 if (process.env.NODE_ENV !== 'production') { ... warnOnce([...]) }

Gates added in this PR

1

  • File: x-data-grid/src/hooks/features/listView/useGridListView.tsx:79
  • Type: warnOnce
  • Description: "listViewColumn must be set when listView is enabled"
  • Gate placement: && process.env.NODE_ENV !== 'production' in if condition

2

  • File: x-data-grid/src/hooks/utils/useGridSelector.ts:62
  • Type: warnOnce
  • Description: "selector called before state initialization"
  • Gate placement: && process.env.NODE_ENV !== 'production' in if condition

3

  • File: x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts:28
  • Type: warnOnce
  • Description: "multi-column sort when disableMultipleColumnsSorting is true"
  • Gate placement: wrapped in if (process.env.NODE_ENV !== 'production') (return-from-sanitize stays unconditional)

4

  • File: x-data-grid/src/internals/utils/propValidation.ts:48
  • Type: warnOnce (loop)
  • Description: All prop validation warnings
  • Gate placement: early return at function entry — strips the entire forEach loop in prod

5

  • File: x-data-grid-pro/src/hooks/features/treeData/utils.ts:34
  • Type: warnOnce (whole fn body)
  • Description: "requires setTreeDataPath() prop"
  • Gate placement: function body wrapped — becomes a no-op in prod

6

  • File: x-data-grid-pro/src/hooks/features/rowReorder/reorderExecutor.ts:49
  • Type: warnOnce
  • Description: "API call resulted in a no-op"
  • Gate placement: wrapped in if block

7

  • File: x-data-grid-pro/src/hooks/features/rowReorder/utils.ts:239
  • Type: warnOnce (in else)
  • Description: "missing onProcessRowUpdateError() handler"
  • Gate placement: promoted to else if (process.env.NODE_ENV !== 'production')

@code-infra-dashboard

code-infra-dashboard Bot commented May 15, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-22461--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid ▼-91B(-0.02%) ▼-32B(-0.03%)
@mui/x-data-grid-pro ▼-246B(-0.05%) ▼-82B(-0.05%)
@mui/x-data-grid-premium ▼-246B(-0.03%) ▼-103B(-0.05%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@sai6855 sai6855 changed the title Restrict warning messages to non-production environments in various components [data grid] Restrict warning messages to non-production environments in various components May 18, 2026
@sai6855 sai6855 added scope: data grid Changes related to the data grid. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels May 18, 2026
@sai6855
sai6855 marked this pull request as ready for review May 18, 2026 06:19
Copilot AI review requested due to automatic review settings May 18, 2026 06:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 warnOnce calls 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') {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here b67f982

Comment on lines +114 to +115
String(cellParams.formattedValue) === '[object Object]' &&
process.env.NODE_ENV !== 'production'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here b67f982

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

],
'error',
);
if (process.env.NODE_ENV !== 'production') {
@sai6855
sai6855 requested review from arminmeh and michelengelen May 18, 2026 06:29
@sai6855
sai6855 requested a review from siriwatknp May 19, 2026 03:12

@michelengelen michelengelen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sai6855

sai6855 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

LGTM

Can you merge PR, I'm not able to do it

@michelengelen
michelengelen enabled auto-merge (squash) June 9, 2026 08:57
@sai6855
sai6855 disabled auto-merge June 9, 2026 09:07
@sai6855
sai6855 enabled auto-merge (squash) June 9, 2026 09:07
@michelengelen
michelengelen disabled auto-merge June 9, 2026 09:40
@michelengelen
michelengelen merged commit 76a87d1 into mui:master Jun 9, 2026
21 checks passed
mbrookes pushed a commit to mbrookes/mui-x that referenced this pull request Jun 27, 2026
const hasItemWithoutOperator = items.some((item) => item.operator == null);

if (hasItemsWithoutIds) {
if (hasItemsWithoutIds && process.env.NODE_ENV !== 'production') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
if (hasItemsWithoutIds && process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production') {
if (hasItemsWithoutIds) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: data grid Changes related to the data grid. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants