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
Move data-theme
from body
tag to html
tag
#2559
Comments
I put the localstorage theme code first thing in the body tag. Works flawlessly without flash of wrong theme. Example: https://github.com/sveltejs/svelte/blob/main/sites/svelte.dev/src/app.html |
Hey @kinglouie Thanks for the comment but like I said, though it happens so quickly on smaller sites, if your site is reasonably large and you will load the body first you might notice a flash of unstyled/wrongly styled content. I think we can both agree determining the style before the |
My concern with this isn't so much a technical one, but one of education. Users will need to be informed that we diverge from Tailwind's recommend here. All their examples show the https://tailwindcss.com/docs/dark-mode#supporting-system-preference-and-manual-selection |
Isn't is the opposite in this case? Instead of the user defining theme and mode in different places they both are applied to the HTML element. The only confusing part is that Skeleton calls |
The value of But what I'm referring to is this:
This modifies the I bring this up as folks that are familiar with Tailwind may be used to setting/adjusting this value on the |
Describe the feature in detail (code, mocks, or screenshots encouraged)
Let's say I want to build a static website (no server) for my blog and I'd like the users to be able to swtich theme.
Skeleton currently has it's theme defined through a data attr on the
body
tag. This means we can simply swap out thedata-theme
attribute and see a theme switch. All goes well and it works perfectly.Now I want to persist the theme change in
localStorage
.Ofcourse because we don't want a flash of unstyled/wrongly styled content we need to load the theme before the
body
element loads. So we dolocalStorage.getItem('theme');
we get the theme and then we need to set it on thebody
element.Uh oh, the
body
element hasn't loaded yet! We now need to wait for thebody
element to load with the wrong theme, and then change it to the theme.current:
proposed:
You can see in the
body
version it's impossible to set the theme beforehand, however, when moving thedata-attribute
tohtml
we can determine and set the theme before thebody
is loaded.What type of pull request would this be?
Enhancement
Provide relevant links or additional information.
No response
The text was updated successfully, but these errors were encountered: