-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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] localeText update does not re-render the grid with new translation #4119
Comments
That's weird, EDIT: |
Related to facebook/react#14099 (comment) Using |
I don't get what is the interest of diff --git a/packages/grid/x-data-grid/src/hooks/core/useGridLocaleText.tsx b/packages/grid/x-data-grid/src/hooks/core/useGridLocaleText.tsx
index 9640ba0c..45321792 100644
--- a/packages/grid/x-data-grid/src/hooks/core/useGridLocaleText.tsx
+++ b/packages/grid/x-data-grid/src/hooks/core/useGridLocaleText.tsx
@@ -1,7 +1,6 @@
import * as React from 'react';
import { GridApiCommunity } from '../../models/api/gridApiCommunity';
import { GridLocaleTextApi } from '../../models/api/gridLocaleTextApi';
-import { useGridApiMethod } from '../utils/useGridApiMethod';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
export const useGridLocaleText = (
@@ -13,14 +12,13 @@ export const useGridLocaleText = (
if (props.localeText[key] == null) {
throw new Error(`Missing translation for key ${key}.`);
}
return props.localeText[key];
},
[props.localeText],
);
- const localeTextApi: GridLocaleTextApi = {
- getLocaleText,
- };
-
- useGridApiMethod(apiRef, localeTextApi, 'LocaleTextApi');
+ if (getLocaleText !== apiRef.current.getLocaleText) {
+ apiRef.current.getLocaleText = getLocaleText
+ }
}; |
With React 18, updating a ref in the render is unsafe. And I don't see how to fix this problem in a React 18 compatible way, without deep changes |
I suppose similar problems can occur whenever we have
|
Since we are using a mutable store, I don't think we can have a reliable solution only with current hooks. To keep the current implementation and support v18 we will need Did someone already had a look at |
I did not yet |
I took a look at this issue and I noticed that it could happen with other props as well if a rerender doesn't occur after the prop change. In the first render after changing the locale, mui-x/packages/grid/x-data-grid/src/hooks/utils/useGridApiMethod.ts Lines 26 to 28 in ffcc4cf
This issue doesn't occur with other props only because we usually call diff --git a/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts b/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts
index 4c71685a..16167707 100644
--- a/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts
@@ -130,8 +130,6 @@ export const useGridSelection = (
const currentModel = gridSelectionStateSelector(apiRef.current.state);
if (currentModel !== model) {
logger.debug(`Setting selection model`);
- apiRef.current.setState((state) => ({ ...state, selection: model }));
- apiRef.current.forceUpdate();
}
},
[apiRef, logger], As a workaround we could trigger a rerender manually once |
The diff below seems to fix this problem: diff --git a/packages/grid/x-data-grid/src/hooks/utils/useGridApiMethod.ts b/packages/grid/x-data-grid/src/hooks/utils/useGridApiMethod.ts
index 10dd4171..12130819 100644
--- a/packages/grid/x-data-grid/src/hooks/utils/useGridApiMethod.ts
+++ b/packages/grid/x-data-grid/src/hooks/utils/useGridApiMethod.ts
@@ -31,5 +31,6 @@ export function useGridApiMethod<Api extends GridApiCommon, T extends Partial<Ap
installMethods();
}, [installMethods]);
+ apiMethodsRef.current = apiMethods;
installMethods();
} I didn't explore the consequences but it might not be recommended, according to #4119 (comment). |
This is a bit of a sore spot for us as we just upgraded to Pro. Are there any workarounds that we can use locally while we await a long-term fix? |
As one of the licensed users, we also found this issue recently. |
We are also facing a similar issue. reproduced the issue here: https://codesandbox.io/s/focused-artem-fytv9q?file=/demo.tsx |
Duplicates
Latest version
Current behavior 😯
From a stackoverflow message
https://codesandbox.io/s/datagridprodemo-material-demo-forked-ozkkjv?file=/demo.js
When changing the
localeText
the grid does not update. It displays the previous language. To have the correct one, we have to for a rerender by clicking on the gridExpected behavior 🤔
When
localText
prop is updated, the components re-render textsSteps to reproduce 🕹
No response
Context 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
Order ID 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: