diff --git a/site/prerender-worker.js b/site/prerender-worker.js index f69d7493a..2afcbcb47 100644 --- a/site/prerender-worker.js +++ b/site/prerender-worker.js @@ -31,7 +31,7 @@ export default async ({ site, url, lang }) => { .replace('', styleTags) .replace(regexHelmet, helmet.title.toString() + helmet.meta.toString()) - const dir = path.join(dirname, 'dist/prerender', site, url) + const dir = path.join(dirname, 'dist/prerender', site, decodeURI(url)) await fs.mkdir(dir, { recursive: true }) await fs.writeFile(path.join(dir, 'index.html'), page) diff --git a/site/prerender.ts b/site/prerender.ts index a7e21d490..1607e8a3b 100644 --- a/site/prerender.ts +++ b/site/prerender.ts @@ -17,7 +17,6 @@ export const pagesToPrerender: { 'mon-entreprise': [ sitePathFr.index, sitePathFr.créer.index, - sitePathFr.gérer.index, sitePathFr.simulateurs.index, sitePathFr.simulateurs.salarié, sitePathFr.simulateurs['chômage-partiel'], @@ -27,12 +26,12 @@ export const pagesToPrerender: { sitePathFr.simulateurs['artiste-auteur'], '/iframes/simulateur-embauche', '/iframes/pamc', - ].map((url) => decodeURI(url)), + ], infrance: [ sitePathEn.index, sitePathEn.simulateurs.salarié, '/iframes/simulateur-embauche', - ].map((url) => decodeURI(url)), + ], } const dev = argv.findIndex((val) => val === '--dev') > -1 @@ -50,7 +49,7 @@ const redirects = await Promise.all( return ` [[redirects]] from = ":SITE_${site === 'mon-entreprise' ? 'FR' : 'EN'}${ - dev ? url : encodeURI(url) + dev ? decodeURI(url) : url }" to = "/${path}" status = 200 diff --git a/site/source/components/utils/useSimulationConfig.ts b/site/source/components/utils/useSimulationConfig.ts index 5d8880a57..93beb3ea0 100644 --- a/site/source/components/utils/useSimulationConfig.ts +++ b/site/source/components/utils/useSimulationConfig.ts @@ -13,6 +13,11 @@ export default function useSimulationConfig( ) { const dispatch = useDispatch() + // Initialize redux store for SSR + if (import.meta.env.SSR) { + dispatch(setSimulationConfig(config ?? {}, path)) + } + const lastConfig = useSelector(configSelector) useEffect(() => { if (config && lastConfig !== config) { diff --git a/site/source/entry-server.tsx b/site/source/entry-server.tsx index 0627dbc1e..7c082272d 100644 --- a/site/source/entry-server.tsx +++ b/site/source/entry-server.tsx @@ -28,9 +28,10 @@ export function render(url: string, lang: 'fr' | 'en') { ) - // first render + // Render to initialize redux store (via useSimulationConfig) ReactDOMServer.renderToString(element) - // second render with the configured engine + + // Render with redux store configured const html = ReactDOMServer.renderToString(element) const styleTags = sheet.getStyleTags()