josefaidt / svelte-themer

A theming engine for your Svelte apps using CSS Variables, persisted.
https://svelte-themer.vercel.app/
MIT License
140 stars 14 forks source link

Dependence on window #27

Closed RamiAwar closed 3 years ago

RamiAwar commented 3 years ago

Hello Jose,

Great writeup on svelte theming! I came here after I failed to persist the themes myself, but it looks like I'll face the same issue here. If I'm using Sapper, or any other kind of SSR, then I won't have access to the window variable in my code (or localStorage or sessionStorage ...). Is there any way to remove that dependency? I see you use it to check the preferred mode of the browser. I noticed your localStorage is properly set inside onMount however!

josefaidt commented 3 years ago

Hi @RamiAwar thank you for the kind words! Yes SSR support would be highly beneficial I'll take a look at removing the dependencies

josefaidt commented 3 years ago

@RamiAwar I've pushed an update to svelte-themer@next which should resolve the issue. Once I am able to confirm I'll publish to 0.4.4

RamiAwar commented 3 years ago

That was fast! I'll test it now!

RamiAwar commented 3 years ago

It's all good on my end! Thanks!

RamiAwar commented 3 years ago

Also in case you haven't seen this already, this is the only warning I see in your code.

"CONTEXT_KEY" is declared in a module script and will not be reactive - svelte(module-script-reactive-declaration)

RamiAwar commented 3 years ago

Also, MediaQueryList.addListener seems deprecated, can be replaced by:

    darkSchemeQuery.addEventListener(
      "change",
      ({ matches }) =>
        mode === "auto" && currentMode.set(matches ? "dark" : "light")
    );
josefaidt commented 3 years ago

I went ahead and updated the event listener. For the context key it appears since it's used in the reactive statement to update the context it's showing that warning. That key does not change therefore I think it's safe to ignore that warning for now. I'll get this merged!

josefaidt commented 3 years ago

merged and available under 0.4.5! let me know if you run into issues! closing for now