BUGFIX (untested): run injected AIR script on every htmx page load

This commit is contained in:
Simon Martens
2025-02-23 20:19:49 +01:00
parent 2ef3eda244
commit c581aa2630

View File

@@ -29,6 +29,29 @@
<link href="/assets/css/remixicon.css" rel="stylesheet" /> <link href="/assets/css/remixicon.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="/assets/css/fonts.css" /> <link rel="stylesheet" type="text/css" href="/assets/css/fonts.css" />
<link rel="stylesheet" type="text/css" href="/assets/style.css" /> <link rel="stylesheet" type="text/css" href="/assets/style.css" />
{{ if .isDev -}}
{{/* INFO: this runs airs injected script on page load, in dev mode */}}
{{/* INFO: Make sure airs proxy runs on port 8081 */}}
<script type="module">
function hookupAIR() {
const port = window.location.port;
if (!port || port !== "8081") {
return;
}
document.body.addEventListener("htmx:afterSwap", (event) => {
if (event.detail.target === document.body) {
const scriptEl = document.querySelector("body > script:last-of-type");
if (scriptEl && scriptEl.textContent.trim()) {
new Function(scriptEl.textContent)();
}
}
});
}
hookupAIR();
</script>
{{- end }}
</head> </head>
<body class="w-full text-lg" hx-ext="response-targets" hx-boost="true"> <body class="w-full text-lg" hx-ext="response-targets" hx-boost="true">