Fix prerender

pull/2249/head
Jérémy Rialland 2022-07-20 20:54:55 +02:00 committed by Jérémy Rialland
parent 5bca6eeb02
commit ce61599db5
4 changed files with 12 additions and 7 deletions

View File

@ -31,7 +31,7 @@ export default async ({ site, url, lang }) => {
.replace('<!--app-style-->', 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)

View File

@ -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

View File

@ -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) {

View File

@ -28,9 +28,10 @@ export function render(url: string, lang: 'fr' | 'en') {
</HelmetProvider>
)
// 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()