-
Notifications
You must be signed in to change notification settings - Fork 317
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
Page is unstyled by default due to dark option #959
Comments
AFAICT so far, none of the premade (but client-side only) solutions are able to avoid the light-to-dark flash when returning to a site, if the site defaults to light and the user switched to dark, or vice versa. I'm not sure, but perhaps one can use media queries to at least fix it for the system setting:
But this requires writing out the styles twice, and I haven't confirmed that this actually works any better. |
@12rambau are you OK with the general approach of having "light" be the default styling? If so either of these options seem reasonable to me:
I'll let you pick which seems better. |
I first want to clearly understand what is happening and reproduce it from my side. The very reason why this is set here ( pydata-sphinx-theme/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html Line 30 in 2dac638
I think forcing the light theme by default will just make it flicker for anyone setting up the dark theme. |
I don't think that prevents displaying anything. It just attempts to set the theme mode very early. I don't know why that doesn't work for us.
OK, I went through all the sites in the gallery, and the results are interesting. Of those sites, few of them are on the latest theme with dark mode enabled, and even fewer have any custom header colours. SciPy sets a custom colour with a general In Matplotlib, we set Looking at the dev console, I see this message:
but I have no idea what is causing that. As a test, I commented out all scripts in If you have any ideas of where to look, I can try out something. Also, this is with Firefox 104.0.2 if that matters. |
Good news, I think I have figured out the problem. The problem is not the theme; the problem is CloudFlare! Its rocket loader defers all scripts, including the one you pointed out above, causing no defaults to get applied initially. What do you think of adding their disabler to that script? It's just adding |
+1 and thanks for figuring it out! |
🍾 I was failing to reproduce it locally and was very surprised by the behavior you were describing
very nice catch indeed
that's armless for everything else so I'm +1 for this one. happy to review a PR |
The instructions for dark/light theming specify:
and I believe this is used in the theme itself. But this means there is no theming applied until the JavaScript runs and sets
data-theme
on the html. If you blockpydata-sphinx-theme.js
(which of course breaks many things), then no theming will be applied.The delay in the JavaScript can cause it to appear as if the theme is lagging, matplotlib/mpl-brochure-site#67 (comment) (ignore the first half of the video which is our bug.)
There are probably multiple ways to fix this. One way to fix it is to (if defaulting to light theme), do
html, html[data-theme="light"]
for the CSS selector. Sincehtml[data-theme="dark"]
is more specific, it will override thehtml
one. The other way is to edit the HTML to set a default on the the element,<html lang="en" data-theme="light">
. Both options will at least give some styling to the page until the JavaScript sets the correct theme. That doesn't work if you revisit a page after setting dark mode though, but this is already flashing anyway.The text was updated successfully, but these errors were encountered: