#issues regarding mode switcher tutorial with viewtransitions

11 messages · Page 1 of 1 (latest)

lethal portal
#

Hi, i'm doing the astro tutorial and i am at https://docs.astro.build/en/tutorial/6-islands/2/.
Unfortunately even tough i've copied the code the mode switcher works with just the first page that loads.
If i remove the viewTransitions the switcher works as intended.
I tried this too:

<button id="themeToggle" transition:persist>
  <svg width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    ....
  </svg>
</button>

This lets the button still work but reset the mode to light each time

Astro Documentation

Tutorial: Build your first Astro blog —
Build a light/dark theme toggle using only JavaScript and CSS

dusty geyserBOT
#
Still waiting for an answer?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

marsh fog
#

I'm having the same issue, I store the theme in localStorage but when ViewTransitions loads a new page the theme is reset. Any help would be appreciated.

I tried explicitly naming the body element and trying to make things persistent but it doesnt seem to remember the theme selected

lethal portal
#

i managed to make it work

#

i didn't understand what the is:inline in the script tag does. so i removed it

#

in short from what i understand using viewTranstitions does execute the script tag only once on mount

#

I fixed the issue putting a document.addEventListener('astro:after-swap', checkTheme); that checks the theme when you swap page as explained here

#

lmk if you have any other issues 😄

marsh fog