Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Reduce bundle size with error messages #12992

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const DataGridPremiumRaw = React.forwardRef(function DataGridPremium<R extends G

useLicenseVerifier('x-data-grid-premium', releaseInfo);

validateProps(props, dataGridPremiumPropValidators);
if (process.env.NODE_ENV !== 'production') {
validateProps(props, dataGridPremiumPropValidators);
}
return (
<GridContextProvider privateApiRef={privateApiRef} props={props}>
<GridRoot
Expand Down
4 changes: 3 additions & 1 deletion packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const DataGridProRaw = React.forwardRef(function DataGridPro<R extends GridValid
const privateApiRef = useDataGridProComponent(props.apiRef, props);
useLicenseVerifier('x-data-grid-pro', releaseInfo);

validateProps(props, propValidatorsDataGridPro);
if (process.env.NODE_ENV !== 'production') {
validateProps(props, propValidatorsDataGridPro);
}
return (
<GridContextProvider privateApiRef={privateApiRef} props={props}>
<GridRoot
Expand Down
5 changes: 3 additions & 2 deletions packages/x-data-grid/src/DataGrid/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ const DataGridRaw = React.forwardRef(function DataGrid<R extends GridValidRowMod
const props = useDataGridProps(inProps);
const privateApiRef = useDataGridComponent(props.apiRef, props);

validateProps(props, propValidators);

if (process.env.NODE_ENV !== 'production') {
validateProps(props, propValidators);
}
return (
<GridContextProvider privateApiRef={privateApiRef} props={props}>
<GridRoot
Expand Down
15 changes: 6 additions & 9 deletions packages/x-data-grid/src/internals/utils/propValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,22 @@ export const propValidatorsDataGrid: PropValidator<DataGridProcessedProps>[] = [
];

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 = <TProps>(props: TProps, validators: PropValidator<TProps>[]) => {
if (process.env.NODE_ENV === 'production') {
return;
}
export function validateProps<TProps>(props: TProps, validators: PropValidator<TProps>[]) {
validators.forEach((validator) => {
const warning = validator(props);
if (warning) {
warnOnce(warning);
}
});
};
}

export const clearWarningsCache = () => {
export function clearWarningsCache() {
warnedOnceCache.clear();
};
}
Loading