#View Transitions "Identifier has already been declared" error

7 messages · Page 1 of 1 (latest)

tiny grove
#

I have an Astro component with an inline script that handles theme toggle logic. I was able to get this working with View Transitions by putting all my logic into a function, and then add an event listener for "astro:beforeload" and passing the function name again there, as recommend in the docs.

Visually this makes the styles persist and the toggle work! However, I'm getting an error on every page navigation in the console, stating "Uncaught SyntaxError: Identifier 'setColorTheme' has already been declared". (setColorTheme is the name of my function).

Any thoughts on how to not have this error? My best guess is it needs a logic check somewhere, but I'm not sure where to put it. The script I have looks like this:
Made a gist with my theme toggle logic: https://gist.github.com/lindakatcodes/9602b6171172d4c9b16ee21fcce75df7

weary robinBOT
#
No-one around right now?

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.

normal scaffold
#

does it work when you delete the is:inline ?

brazen rose
normal scaffold