diff --git a/source/Provider.tsx b/source/Provider.tsx index acbaf27ee..8f6d741b8 100644 --- a/source/Provider.tsx +++ b/source/Provider.tsx @@ -15,7 +15,7 @@ import { applyMiddleware, compose, createStore, Middleware, Store } from 'redux' import thunk from 'redux-thunk' import Tracker from 'Tracker' import { Rules } from './rules' -import { inIframe } from './utils' +import { inIframe, getSessionStorage } from './utils' declare global { interface Window { @@ -93,11 +93,11 @@ export default function Provider({ ...(reduxMiddlewares ?? []) ) ) - useEffect(() => { - if (language) { - i18next.changeLanguage(language) - } - }, []) + if (language) { + getSessionStorage()?.setItem('lang', language) + i18next.changeLanguage(language) + } + if (language && initialStore) initialStore.lang = language const store = createStore(reducers, initialStore, storeEnhancer) onStoreCreated?.(store) diff --git a/source/sites/mon-entreprise.fr/App.tsx b/source/sites/mon-entreprise.fr/App.tsx index fe425079b..a74ede9e2 100644 --- a/source/sites/mon-entreprise.fr/App.tsx +++ b/source/sites/mon-entreprise.fr/App.tsx @@ -7,13 +7,13 @@ import { import { SitePathsContext } from 'Components/utils/SitePathsContext' import Engine from 'Engine' import 'iframe-resizer' -import React, { useContext, useEffect, useMemo } from 'react' +import React, { useContext, useMemo } from 'react' import { Helmet } from 'react-helmet' import { useTranslation } from 'react-i18next' import { useSelector } from 'react-redux' import { Route, Switch } from 'react-router-dom' import createSentryMiddleware from 'redux-sentry-middleware' -import { Rules } from 'Rules' +import rulesFr, { Rules } from 'Rules' import { configSituationSelector, situationSelector @@ -29,7 +29,7 @@ import { retrievePersistedSimulation } from '../../storage/persistSimulation' import Tracker, { devTracker } from '../../Tracker' -import { getSessionStorage, inIframe } from '../../utils' +import { inIframe } from '../../utils' import './App.css' import Footer from './layout/Footer/Footer' import Header from './layout/Header' @@ -78,20 +78,16 @@ const middlewares = [ trackSimulatorActions(tracker) ] -type InFranceRouteProps = { +type RootProps = { basename: ProviderProps['basename'] language: ProviderProps['language'] rules: Rules } -function InFranceRoute({ basename, language, rules }: InFranceRouteProps) { - useEffect(() => { - getSessionStorage()?.setItem('lang', language) - }, [language]) - +function Root({ basename, language, rules }: RootProps) { // Hot reload rules if (process.env.NODE_ENV !== 'production' && language === 'fr') { - rules = rules + rules = rulesFr } const paths = constructLocalizedSitePath(language) @@ -199,11 +195,11 @@ const App = () => { ) } -let ExportedApp = InFranceRoute +let ExportedApp = Root if (process.env.NODE_ENV !== 'production') { const { hot } = require('react-hot-loader') - ExportedApp = hot(module)(InFranceRoute) + ExportedApp = hot(module)(Root) } export default ExportedApp