You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Uncaught SyntaxError: Identifier 'templ_reloadSrc' has already been declared (at script.js:1:1)
This is because when we hit back button, htmx restores the html elements from localStorage which includes our injected script tag <script src="/_templ/reload/script.js"></script>. And it gets re-evaluated:
Problem
To reproduce this problem, one can setup a basic htmx project. We can use https://github.com/jackielii/templ-live-reload-example/
Once we
make live
We can see error in the console saying:
This is because when we hit back button, htmx restores the html elements from localStorage which includes our injected script tag
<script src="/_templ/reload/script.js"></script>
. And it gets re-evaluated:templ_reloadSrc
is in global scope, thus the errorProposed solution
This doesn't cause any trouble, but having the error in the console is not ideal.
I think the fix is to either:
<head>
sectionI think option 2 is better.
The text was updated successfully, but these errors were encountered: