-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Enforcing dark mode not working in production #10308
Comments
I don't have any issues trying to reproduce your configuration locally on my macbook with docker, the website loads by default with darkmode theme enabled |
I tried it now with a local docker NGINX too and it worked. Could lead a setting in NGINX to this problem? |
We don't know, what could be the problem, but it seems solved. If you (and us) can reproduce the problem deterministically, we'll reopen, otherwise we assume it was a human mistake |
I'm sorry but it is not solved. I still have the problem on my live system. I tried only with a local docker nginx and with this the problem was not happening. |
Did you try loading it in private browsing? Did you try any other hosting solution than Nginx? If this is specific to one setup it doesn't sound like a Docusaurus bug and should not be reported here. |
If we cannot see the live system, its source code, and config, we cannot help more. If your domain host other sites, it is possible that you encounter a storage key conflict, see https://docusaurus.io/blog/releases/3.4#site-storage---experimental for details |
I also think that it can not be Docusaurus, because locally it works. That is really weird. Yes, I tried private browsing @Josh-Cena, with no luck. @slorber I'll check that with the key conflict. And I will copy my production config into a docker container to play around with it. I'll come back to you with the result. Thanks for the help. |
The easiest for us is that you share the URL of your live deployment. |
@slorber Sorry, late reply. Something else popped up. |
Your site is served with a CSP header that prevents our inline script from running, you can see errors in the console logs.
Here's what this script is doing FYI, it is required to get the theme work and avoid a flash of wrong theme before React hydrates !(function () {
function t(t) {
document.documentElement.setAttribute("data-theme", t);
}
var e =
(function () {
try {
return new URLSearchParams(window.location.search).get(
"docusaurus-theme",
);
} catch (t) {}
})() ||
(function () {
try {
return window.localStorage.getItem("theme");
} catch (t) {}
})();
t(null !== e ? e : "dark");
})(),
(function () {
try {
const n = new URLSearchParams(window.location.search).entries();
for (var [t, e] of n)
if (t.startsWith("docusaurus-data-")) {
var a = t.replace("docusaurus-data-", "data-");
document.documentElement.setAttribute(a, e);
}
} catch (t) {}
})(); |
Hey @slorber, thank you so much. I totally overlooked this error. It works now :) . |
Afaik it's not really possible to remove the inline scripts. At best we could make it so that it works for your specific use-case by hardcoding the dark This has been explained a bit here: #10231 |
Ah, ok. For me it is fine and I also support your point of view in #10231. I'm not an expert in XSS or general website hacking, but I also do not really see an attack surface in this kind of website. Thanks for the fast help and Docusaurus. Really appreciate it. |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
Hello everyone,
I hope someone can point me to a solution. Searching already for hours.
I try to load my website only in dark mode and use for that the settings:
It is working fine locally (using Webstorm) with
docusaurus start
anddocusaurus build & docusaurus serve
. But if I deploy the website to my NGINX server, the light mode is loading. If I enable the switch and activate the dark mode, everything works as expected. I can not find a solution to enforce the dark mode in production.Any help is more then welcome.
Best
Martin
Reproducible demo
No response
Steps to reproduce
Expected behavior
Dark mode is always enabled
Actual behavior
Website loads with light mode.
Your environment
Self-service
The text was updated successfully, but these errors were encountered: