fix(frontend): Fix MUI hydration mismatch in ReduxProvider
Issue: MUI v7 CircularProgress was causing hydration mismatch warnings due to different CSS class names between server and client renders. Solution: Only render the MUI loading component on the client side using isClient state flag. This prevents SSR hydration issues while maintaining the same functionality. Changes: - Added useState to track client-side rendering - Conditionally render CircularProgress only on client - Server now renders null for loading state (no hydration mismatch)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import { PersistGate } from 'redux-persist/integration/react';
|
import { PersistGate } from 'redux-persist/integration/react';
|
||||||
import { store, persistor } from '@/store/store';
|
import { store, persistor } from '@/store/store';
|
||||||
@@ -9,8 +9,11 @@ import { CircularProgress, Box } from '@mui/material';
|
|||||||
|
|
||||||
export function ReduxProvider({ children }: { children: React.ReactNode }) {
|
export function ReduxProvider({ children }: { children: React.ReactNode }) {
|
||||||
const cleanupRef = useRef<(() => void) | null>(null);
|
const cleanupRef = useRef<(() => void) | null>(null);
|
||||||
|
const [isClient, setIsClient] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setIsClient(true);
|
||||||
|
|
||||||
// Setup network detection
|
// Setup network detection
|
||||||
cleanupRef.current = setupNetworkDetection(store.dispatch);
|
cleanupRef.current = setupNetworkDetection(store.dispatch);
|
||||||
|
|
||||||
@@ -26,16 +29,18 @@ export function ReduxProvider({ children }: { children: React.ReactNode }) {
|
|||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<PersistGate
|
<PersistGate
|
||||||
loading={
|
loading={
|
||||||
<Box
|
isClient ? (
|
||||||
sx={{
|
<Box
|
||||||
display: 'flex',
|
sx={{
|
||||||
justifyContent: 'center',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
justifyContent: 'center',
|
||||||
minHeight: '100vh'
|
alignItems: 'center',
|
||||||
}}
|
minHeight: '100vh'
|
||||||
>
|
}}
|
||||||
<CircularProgress />
|
>
|
||||||
</Box>
|
<CircularProgress />
|
||||||
|
</Box>
|
||||||
|
) : null
|
||||||
}
|
}
|
||||||
persistor={persistor}
|
persistor={persistor}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user