Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dsfr): ne pas utiliser deux fois la balise HTML #6246

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions packages/code-du-travail-frontend/src/modules/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import { SkipLinks } from "./SkipLinks";

export const DsfrLayout = ({ children }: { children: React.ReactNode }) => {
return (
<html>
<body>
<SkipLinks />
<Header />
<main className={fr.cx("fr-container")} id="main">
{children}
</main>
<NeedMoreInfo />
<Footer />
</body>
</html>
<>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le soucis est que l'on utilise la balise HTML et BODY alors qu'elles sont déjà présentes dans le layout de base :

<html {...getHtmlAttributes({ defaultColorScheme, lang })}>

React-dsfr utilise la balise html pour stocker les infos sur le mode en cours (dark / light) pour synchro le client et le serveur. Si tu as 2 HTML, next.js semblent prendre le dernier et écraser l'ancien avec le nouveau (et affiche un warning que l'on avait loupé). Cela ne se produit que lorsque l'on navigue de page en page. Au premier chargement, il semble utiliser la première balise HTML (render server vs client ?).
Du coup, on écrase les valeurs de react-dsfr qui se perd sur le dark mode et génère des erreurs et un comportement étrange.

<SkipLinks />
<Header />
<main className={fr.cx("fr-container")} id="main">
{children}
</main>
<NeedMoreInfo />
<Footer />
</>
);
};
Loading