fix outerHTML body swapping issue

fixes https://github.com/bigskysoftware/htmx/issues/2639
This commit is contained in:
Carson Gross 2024-06-18 10:28:53 -06:00
parent d35222446d
commit f3ae976aa2
4 changed files with 22 additions and 0 deletions

View File

@ -1626,6 +1626,9 @@ var htmx = (function() {
* @param {HtmxSettleInfo} settleInfo
*/
function swapOuterHTML(target, fragment, settleInfo) {
if (target.tagName === "BODY") { // special case the body to innerHTML because DocumentFragments can't contain a body elt unfortunately
return swapInnerHTML(target, fragment, settleInfo);
}
/** @type {Node} */
let newElt
const eltBeforeNewContent = target.previousSibling

View File

@ -0,0 +1,3 @@
<body>
<h1>A New Body, should still have a red border</h1>
</body>

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Body Swap Test</title>
<script type="application/javascript" src="../../../src/htmx.js"></script>
</head>
<body style="padding: 20px; font-family: sans-serif;border: 6px solid red">
<button hx-get="body.html"
hx-target="body"
hx-swap="outerHTML">
Swap Body With outerHTML
</button>
</body>
</html>

View File

@ -17,6 +17,7 @@
<li><a href="poll-condition-test.html">Poll Conditionals</a></li>
<li><a href="poll-clears-on-reinit-test.html">Polling Cancels On Reprocessing</a></li>
<li><a href="cache-buster">Cache Busting Test</a></li>
<li><a href="body-swap">Body Swap Test</a></li>
<li>Scroll Tests
<ul>
<li><a href="scroll-test-eventHandler.html">Scroll Event Handler</a></li>