Skip to content

Commit

Permalink
[DataGrid] Don't evaluate hasEval when disableEval is set (@reihwald) (
Browse files Browse the repository at this point in the history
…#11553)

Co-authored-by: reihwald <[email protected]>
  • Loading branch information
github-actions[bot] and reihwald authored Jan 3, 2024
1 parent e61c0b9 commit 31fa58f
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/pages/x/api/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"disableColumnResize": { "type": { "name": "bool" }, "default": "false" },
"disableColumnSelector": { "type": { "name": "bool" }, "default": "false" },
"disableDensitySelector": { "type": { "name": "bool" }, "default": "false" },
"disableEval": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleColumnsFiltering": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleColumnsSorting": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleRowSelection": { "type": { "name": "bool" }, "default": "false" },
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"disableColumnResize": { "type": { "name": "bool" }, "default": "false" },
"disableColumnSelector": { "type": { "name": "bool" }, "default": "false" },
"disableDensitySelector": { "type": { "name": "bool" }, "default": "false" },
"disableEval": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleColumnsFiltering": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleColumnsSorting": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleRowSelection": { "type": { "name": "bool" }, "default": "false" },
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"disableColumnMenu": { "type": { "name": "bool" }, "default": "false" },
"disableColumnSelector": { "type": { "name": "bool" }, "default": "false" },
"disableDensitySelector": { "type": { "name": "bool" }, "default": "false" },
"disableEval": { "type": { "name": "bool" }, "default": "false" },
"disableMultipleRowSelection": {
"type": { "name": "bool" },
"default": "false (`!props.checkboxSelection` for MIT Data Grid)"
},
"disableRowSelectionOnClick": { "type": { "name": "bool" }, "default": "false" },
"disableVirtualization": { "type": { "name": "bool" }, "default": "false" },
"editMode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"disableColumnResize": "If <code>true</code>, resizing columns is disabled.",
"disableColumnSelector": "If <code>true</code>, hiding/showing columns is disabled.",
"disableDensitySelector": "If <code>true</code>, the density selector is disabled.",
"disableEval": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"disableMultipleColumnsFiltering": "If <code>true</code>, filtering with multiple columns is disabled.",
"disableMultipleColumnsSorting": "If <code>true</code>, sorting with multiple columns is disabled.",
"disableMultipleRowSelection": "If <code>true</code>, multiple selection using the Ctrl or CMD key is disabled.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"disableColumnResize": "If <code>true</code>, resizing columns is disabled.",
"disableColumnSelector": "If <code>true</code>, hiding/showing columns is disabled.",
"disableDensitySelector": "If <code>true</code>, the density selector is disabled.",
"disableEval": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"disableMultipleColumnsFiltering": "If <code>true</code>, filtering with multiple columns is disabled.",
"disableMultipleColumnsSorting": "If <code>true</code>, sorting with multiple columns is disabled.",
"disableMultipleRowSelection": "If <code>true</code>, multiple selection using the Ctrl or CMD key is disabled.",
Expand Down
5 changes: 5 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
"deprecated": "",
"typeDescriptions": {}
},
"disableEval": {
"description": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"deprecated": "",
"typeDescriptions": {}
},
"disableMultipleColumnsFiltering": {
"description": "If <code>true</code>, filtering with multiple columns is disabled.",
"deprecated": "",
Expand Down
1 change: 1 addition & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"disableColumnResize": "If <code>true</code>, resizing columns is disabled.",
"disableColumnSelector": "If <code>true</code>, hiding/showing columns is disabled.",
"disableDensitySelector": "If <code>true</code>, the density selector is disabled.",
"disableEval": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"disableMultipleColumnsFiltering": "If <code>true</code>, filtering with multiple columns is disabled.",
"disableMultipleColumnsSorting": "If <code>true</code>, sorting with multiple columns is disabled.",
"disableMultipleRowSelection": "If <code>true</code>, multiple selection using the Ctrl or CMD key is disabled.",
Expand Down
1 change: 1 addition & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"disableColumnResize": "If <code>true</code>, resizing columns is disabled.",
"disableColumnSelector": "If <code>true</code>, hiding/showing columns is disabled.",
"disableDensitySelector": "If <code>true</code>, the density selector is disabled.",
"disableEval": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"disableMultipleColumnsFiltering": "If <code>true</code>, filtering with multiple columns is disabled.",
"disableMultipleColumnsSorting": "If <code>true</code>, sorting with multiple columns is disabled.",
"disableMultipleRowSelection": "If <code>true</code>, multiple selection using the Ctrl or CMD key is disabled.",
Expand Down
5 changes: 5 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
"deprecated": "",
"typeDescriptions": {}
},
"disableEval": {
"description": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"deprecated": "",
"typeDescriptions": {}
},
"disableMultipleColumnsFiltering": {
"description": "If <code>true</code>, filtering with multiple columns is disabled.",
"deprecated": "",
Expand Down
1 change: 1 addition & 0 deletions docs/translations/api-docs/data-grid/data-grid-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"disableColumnMenu": "If <code>true</code>, the column menu is disabled.",
"disableColumnSelector": "If <code>true</code>, hiding/showing columns is disabled.",
"disableDensitySelector": "If <code>true</code>, the density selector is disabled.",
"disableEval": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"disableRowSelectionOnClick": "If <code>true</code>, the selection on click on a row or cell is disabled.",
"disableVirtualization": "If <code>true</code>, the virtualization is disabled.",
"editMode": "Controls whether to use the cell or row editing.",
Expand Down
1 change: 1 addition & 0 deletions docs/translations/api-docs/data-grid/data-grid-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"disableColumnMenu": "If <code>true</code>, the column menu is disabled.",
"disableColumnSelector": "If <code>true</code>, hiding/showing columns is disabled.",
"disableDensitySelector": "If <code>true</code>, the density selector is disabled.",
"disableEval": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"disableRowSelectionOnClick": "If <code>true</code>, the selection on click on a row or cell is disabled.",
"disableVirtualization": "If <code>true</code>, the virtualization is disabled.",
"editMode": "Controls whether to use the cell or row editing.",
Expand Down
10 changes: 10 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
"deprecated": "",
"typeDescriptions": {}
},
"disableEval": {
"description": "If <code>true</code>, <code>eval()</code> is not used for performance optimization.",
"deprecated": "",
"typeDescriptions": {}
},
"disableMultipleRowSelection": {
"description": "If <code>true</code>, multiple selection using the Ctrl/CMD or Shift key is disabled. The MIT DataGrid will ignore this prop, unless <code>checkboxSelection</code> is enabled.",
"deprecated": "",
"typeDescriptions": {}
},
"disableRowSelectionOnClick": {
"description": "If <code>true</code>, the selection on click on a row or cell is disabled.",
"deprecated": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ DataGridPremiumRaw.propTypes = {
/**
* If `true`, `eval()` is not used for performance optimization.
* @default false
* @ignore - do not document
*/
disableEval: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ DataGridProRaw.propTypes = {
/**
* If `true`, `eval()` is not used for performance optimization.
* @default false
* @ignore - do not document
*/
disableEval: PropTypes.bool,
/**
Expand Down
1 change: 0 additions & 1 deletion packages/grid/x-data-grid/src/DataGrid/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ DataGridRaw.propTypes = {
/**
* If `true`, `eval()` is not used for performance optimization.
* @default false
* @ignore - do not document
*/
disableEval: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ import {
const globalScope = (typeof window === 'undefined' ? globalThis : window) as any;
const evalCode = globalScope[atob('ZXZhbA==')] as <T>(source: string) => T;

let hasEval: boolean;
try {
hasEval = evalCode<boolean>('true');
} catch (_: unknown) {
hasEval = false;
}
let hasEval: boolean | undefined;

const getHasEval = () => {
if (hasEval !== undefined) {
return hasEval;
}

try {
hasEval = evalCode<boolean>('true');
} catch (_: unknown) {
hasEval = false;
}

return hasEval;
};

type GridFilterItemApplier =
| {
Expand Down Expand Up @@ -272,7 +281,7 @@ const buildAggregatedFilterItemsApplier = (
return null;
}

if (!hasEval || disableEval) {
if (disableEval || !getHasEval()) {
// This is the original logic, which is used if `eval()` is not supported (aka prevented by CSP).
return (row, shouldApplyFilter) => {
const resultPerItemId: GridFilterItemResult = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export interface DataGridPropsWithDefaultValues {
/**
* If `true`, `eval()` is not used for performance optimization.
* @default false
* @ignore - do not document
*/
disableEval: boolean;
/**
Expand Down

0 comments on commit 31fa58f

Please sign in to comment.