-
Notifications
You must be signed in to change notification settings - Fork 36
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
refactor: fix the SSR/CSR mismatch #146
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks! |
Alternatively, you could use themed-images, which might be the best solution aside from the aforementioned approaches and using: // You might be fine with the following, but use at your own risks,
// and be aware it is likely to create issues down the line
const isDarkMode = document.documentElement.getAttribute('data-theme') === "dark"; Docusaurus doesn't have good support for "legacy CSS-in-JS libs" (StyledComponents, Emotion, JSS, MUI...), that require collecting styles during the rendering process (see also facebook/docusaurus#3236). Warning However, you may have noticed that The Lives
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though the compilation build workflow is successful, the actual effect is still problematic(see also #146 (comment))
Thanks for your work :) @ErKeLost take a look? |
@HsiangNianian thank you for your work,I will try to repair the next work |
What happened?
Due to the CSS not being written in a format supported by Webpack1, I imported
postcss-preset-env
(a10ec67) and created thecustomPostCssPlugin
function(091a16f) (the code is provided below) to enable runtime plugins, achieving the goal of using preset environment CSS. This has clearly been effective.The Changes
Important
There is one remaining warning, similar to the previous ones.
This final error is still due to the CSS format, but it cannot be detected by the customPostCssPlugin.
So you can continue to make modifications from this perspective to try to get the compilation build workflow to pass. Since it's already quite late (USTC +8), I currently don't have the ability to further investigate any suspicious CSS syntax.
This is the everything about WA.
Literally, I noticed the error about
useColorMode()
in prod mode. Values derived from useColorMode() can be stale when rendering in prod mode, so we have to avoid to useimport { useColorMode } from '@docusaurus/theme-common';
and this is likely a react hydration problem.Asfaik, react 18 introduces a onRecoverableError callback which usually notice you of hydration mismatches.
In this case we can't technically init react state with the correct value, but instead should always init it to the default color mode, and then trigger a new re-render to fix it after hydration.
This should fix the SSR/CSR mismatch, but this is a bit annoying unfortunately, as it will mean some components will render first with the wrong colorMode and then eventually re-render with the right one.
Footnotes
https://github.com/webpack/webpack/issues/14893 ↩