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