ancient-shoe-86801
11/30/2022, 9:05 PMancient-shoe-86801
11/30/2022, 9:11 PMgreen-activity-6102
11/30/2022, 11:00 PMhx-boost
swaps innerHTML
on the <body>
tag, which means if the source page made any modifications to that <body>
tag they carry over post-swap.
With Bootstrap modals, when a modal opens it puts overflow:hidden
on the <body>
to prevent you from scrolling the body while the modal is open. And so if you follow a boosted link while the modal is open, on the post-swapped page you can't scroll anymore.
Is there a way to configure hx-boost
to use outerHTML
? I tried adding hx-swap="outerHTML"
to the boosted link and that didn't workegreen-activity-6102
11/30/2022, 11:18 PMhx-swap="delete"
works as expected (i get a fully blank page)green-activity-6102
11/30/2022, 11:18 PMhtmx:beforeSwap
but i dont see it in the event.details.requestConfig
mysterious-toddler-20573
11/30/2022, 11:26 PMmysterious-toddler-20573
11/30/2022, 11:26 PMgreen-activity-6102
12/01/2022, 12:12 AMhead-support
extension here, not sure if that mattersmysterious-toddler-20573
12/01/2022, 1:17 AMmorph
swap it should merge the attributesmysterious-toddler-20573
12/01/2022, 1:17 AMmysterious-toddler-20573
12/01/2022, 1:17 AMgreen-activity-6102
12/01/2022, 1:18 AMgreen-activity-6102
12/01/2022, 1:18 AMgreen-activity-6102
12/01/2022, 1:21 AMgreen-activity-6102
12/01/2022, 1:25 AMhtmx:beforeSwap
and manually closing the modalgreen-activity-6102
12/01/2022, 1:27 AMhead-support
with boosted links... if you have anything in the head that establishes event listeners, those listeners will get re-initialized every time the <head>
gets swapped back in... so if you navigate to the same page multiple times in a session then the listeners start to stack up and fire multiple timesgreen-activity-6102
12/01/2022, 1:28 AMmysterious-toddler-20573
12/01/2022, 1:30 AMgreen-activity-6102
12/01/2022, 1:31 AMmysterious-toddler-20573
12/01/2022, 1:31 AMgreen-activity-6102
12/01/2022, 1:36 AMhtml
<!-- /first-page -->
<html>
<head>
<script>
$(document).on("htmx:beforeSwap", function(){
console.log("Hello from first page");
});
</script>
</head>
<body hx-ext="head-support">
<a href="/another-page" hx-boost="true">
</body>
</html>
<!-- /another-page -->
<html>
<head>
<script>
$(document).on("htmx:beforeSwap", function(){
console.log("Hello from 2nd page");
});
</script>
</head>
<body hx-ext="head-support">
<a href="/first-page" hx-boost="true">
</body>
</html>
green-activity-6102
12/01/2022, 1:37 AM/first-page
it attaches the beforeSwap event listener, when you navigate to /second-page
you'll see Hello from first page
in the console. When you navigate back to /first-page
you'll see Hello from first page
AND Hello from 2nd page
because first listener wasn't removed when you swapped to the 2nd pagegreen-activity-6102
12/01/2022, 1:38 AMhtml
<head>
<script>
$(document).off("htmx:beforeSwap");
$(document).on("htmx:beforeSwap", function(){
console.log("Hello from 2nd page");
});
</script>
</head>
This fails silently if there arent any listeners initializedmysterious-toddler-20573
12/01/2022, 1:39 AMgreen-activity-6102
12/01/2022, 1:40 AMmysterious-toddler-20573
12/01/2022, 1:41 AMhx-preserve="true"
on that script, it should preserve it and not re-execute it even if it appears againgreen-activity-6102
12/01/2022, 1:41 AMgreen-activity-6102
12/01/2022, 1:42 AM<script>
tag into the newly swapped page? because i dont really want that (it might have other things beside event listeners)mysterious-toddler-20573
12/01/2022, 1:42 AM