korbit-ai[bot] commented on code in PR #34268:
URL: https://github.com/apache/superset/pull/34268#discussion_r2222269113
##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/components/ChartWrapper.tsx:
##########
@@ -39,13 +42,21 @@ export const ChartWrapper: FC<ChartWrapperProps> = ({
getChartFromRegistry(vizType);
}, [vizType]);
+ // Create a mock store that is needed by
+ // eCharts components to access the locale.
+ const mockStore = configureStore({
+ reducer: (state = { common: { locale } }) => state,
+ });
Review Comment:
### Redux Store Recreation On Every Render <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The Redux store is recreated on every render, which can cause unnecessary
re-renders of child components and potential loss of state consistency.
###### Why this matters
Creating a new store on each render breaks Redux's state management
guarantees and can lead to performance issues as components re-render
unnecessarily.
###### Suggested change ∙ *Feature Preview*
Move the store creation outside the component or use useMemo to memoize it:
```typescript
const ChartWrapper: FC<ChartWrapperProps> = ({
vizType,
theme,
height,
width,
chartConfig,
locale,
}) => {
const mockStore = useMemo(
() =>
configureStore({
reducer: (state = { common: { locale } }) => state,
}),
[locale]
);
// ... rest of the component
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/52cf5b35-1370-4bd7-87c1-b1608b710c40/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/52cf5b35-1370-4bd7-87c1-b1608b710c40?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/52cf5b35-1370-4bd7-87c1-b1608b710c40?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/52cf5b35-1370-4bd7-87c1-b1608b710c40?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/52cf5b35-1370-4bd7-87c1-b1608b710c40)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:5c6a74ab-a5ff-4d24-a729-bc70acd3ed35 -->
[](5c6a74ab-a5ff-4d24-a729-bc70acd3ed35)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]