Replies: 5 comments 1 reply
-
I wrote a detailed response but forgot to send it for some reason. Now I'm out, I'll send it later. But just to tell you I've pushed a patch with the fix you suggested about the isDark client state. |
Beta Was this translation helpful? Give feedback.
-
Hello @moroine,
I'm not sure what level you're speaking from here. In Once this component is hydrated, DSFR JS starts and begins observing the DOM, potentially annotating newly added elements synchronously. That’s what can cause hydration errors—especially with streamed HTML chunks. When you mention the 300ms timeout, I assume you're referring to a delay inside In any case, we both agree: relying on timeouts is not an acceptable solution.
Good catch! I'll revisit the implementation. You're right: on the first render, we should continue using
That flickering only affects components using CSS-in-JS (like MUI). Native DSFR components, which rely on CSS variables, don’t flicker because the root HTML attribute is set early via
That's not a solution—it’s the only viable solution. It's a well-known limitation of CSS-in-JS: the only way to avoid flickering when implementing dark mode is to SSR different versions of the page depending on the user's preference. For the Page Router, I provided However, I didn’t port it to the App Router, because it’s not reasonable. It causes the server to regenerate pages for every request and, even then, it only works on subsequent loads—not the initial one.
This is already implemented. The only practical way forward here is to use patch-package and apply the necessary adjustments to support React Server Components and streaming properly. The idea would be to provide an attribute or a signal that tells DSFR when it's safe to mutate a DOM element. I’ll explore how feasible this is in practice. |
Beta Was this translation helpful? Give feedback.
-
Hello @garronej,
When I mean adding
I agree.
Isn't it possible to consider a PR on the
Maybe we can propose such an improvement ? I was thinking about the issue over the weekend, and I was wondering if we could have in components from But if we could submit a PR to
Note Looks like theses solutions requires to update the |
Beta Was this translation helpful? Give feedback.
-
@garronej any suggestion about the best way to handle this ? |
Beta Was this translation helpful? Give feedback.
-
@moroine I'm going to focus on react-dsfr for a bit to implement a key feature: The goal is to make it easy for public service apps to be white-labeled and deployed in other contexts. I'll likely be patching @gouvfr/dsfr with patch-package during this work — I can also take a look at server component streaming in parallel. |
Beta Was this translation helpful? Give feedback.
-
I'd like to discuss about NextJs Server Component Streaming support following the comment #305 (comment)
I spent quite some time to dig-in both react-dsfr & dsfr codebases.
I understand the limitation regarding server sub-components, and I don't want to disable user interactions before everything is loaded.
From what I understand of dsfr, once activated, DSFR observes DOM modifications to integrate itself: https://github.com/GouvernementFR/dsfr/blob/5c3d27f9b0d5c060b411fcdfff663609f7eeb6fc/src/dsfr/core/script/api/modules/stage/stage.js#L62-L96
setTimeout
of 300ms, then there are no more issues. But this is a rather unacceptable solution. Ideally, it should be possible to determine when hydration is complete to act as a useEffect would.data-fr-js-xx
attributes: https://github.com/GouvernementFR/dsfr/blob/5c3d27f9b0283f02d674908e4ed93742833f49bf17a7/src/dsfr/core/script/api/modules/register/instance.js#L47 If I remove this line, everything works fine. I can't understand the purpose of this attribute (it doesn't seem to be read in the dsfr code). Ideally, if DSFR needs to keep such a reference, they could use a WeakMap 🤔Regarding the hydration problem related to
useIsDark
, it's because the initialization value ofisDark
is inconsistent with the server once DSFR is initialized:react-dsfr/src/useIsDark/client.ts
Lines 57 to 59 in 7789b02
But the problem, I think, will be a darkMode flickering on loading. A solution could be to save the darkMode in a cookie, which could be read by the server component to correctly initialize dark mode.
Otherwise, we could simply add a
suppressHydratationWarning
to the DSFR components: https://legacy.reactjs.org/docs/dom-elements.html#suppresshydrationwarning?"Beta Was this translation helpful? Give feedback.
All reactions