Skip to content

Commit

Permalink
fix: Set global js injection init flag
Browse files Browse the repository at this point in the history
Prevent the injected js from being executed multiple times.
Make sure it only executes once.
  • Loading branch information
romshark committed Jul 8, 2024
1 parent be01249 commit 65d6dd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/server/templates.templ
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ templ jsInjection(printDebugLogs bool, wsEventsEndpoint string) {
})
<script type="text/javascript">
(() => {
if (window._templier__jsInjection_initialized === true) {
return
}
let params = JSON.parse(
document.getElementById('_templier__jsInjection').textContent
)
Expand Down Expand Up @@ -161,6 +164,7 @@ templ jsInjection(printDebugLogs bool, wsEventsEndpoint string) {
}

connectWebsocket()
window._templier__jsInjection_initialized = true
})();
</script>
}
2 changes: 1 addition & 1 deletion internal/server/templates_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 65d6dd4

Please sign in to comment.