theme-controller resets and stops working on session history back #3037
Unanswered
keksiskela
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Can you please provide a minimum reproduction link? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using the simple swap controller with some javascript to store and retrieve set theme from local storage and to update both the document root
data-theme
attribute and the checkbox; it works as expected until I navigate back in the session history, from there the theme-controller reverts to the default swap-off while the theme remains the same even if the checkbox is checked and the root<html data-theme='foo'>
attribute is set to the correct theme, and theme change doesn't respond anymore to further clicks, only the icon changes; it starts working again only on page refresh, which causes annoying flickering if set withlocation.reload()
onpopstate
as a temporary hack in the javascript. I'm not a professional web-developer, just an amateur: what am I doing wrong? The javascript is just a vanillaaddEventListener()
on window load/reload and on checkbox change, storing and updating attributes and values, so I don't think the problem is there...I'm using htmx to make internal navigation responsive, and it does store some cache data, but the data stored is correct relative to the theme, and the problem occurs even disabling said htmx cache. No web search has helped me understand the issue, and I've debugged my code to the best of my knowledge.
Beta Was this translation helpful? Give feedback.
All reactions