From f3ae976aa2e1dd425b11303adf22ae90712be455 Mon Sep 17 00:00:00 2001 From: Carson Gross Date: Tue, 18 Jun 2024 10:28:53 -0600 Subject: fix outerHTML body swapping issue fixes https://github.com/bigskysoftware/htmx/issues/2639 --- src/htmx.js | 3 +++ test/manual/body-swap/body.html | 3 +++ test/manual/body-swap/index.html | 15 +++++++++++++++ test/manual/index.html | 1 + 4 files changed, 22 insertions(+) create mode 100644 test/manual/body-swap/body.html create mode 100644 test/manual/body-swap/index.html diff --git a/src/htmx.js b/src/htmx.js index 1f0b622f..bebe3785 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -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 diff --git a/test/manual/body-swap/body.html b/test/manual/body-swap/body.html new file mode 100644 index 00000000..32277c86 --- /dev/null +++ b/test/manual/body-swap/body.html @@ -0,0 +1,3 @@ + +

A New Body, should still have a red border

+ diff --git a/test/manual/body-swap/index.html b/test/manual/body-swap/index.html new file mode 100644 index 00000000..406daf54 --- /dev/null +++ b/test/manual/body-swap/index.html @@ -0,0 +1,15 @@ + + + + + Body Swap Test + + + + + + diff --git a/test/manual/index.html b/test/manual/index.html index 0c7d5c11..cda51718 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -17,6 +17,7 @@
  • Poll Conditionals
  • Polling Cancels On Reprocessing
  • Cache Busting Test
  • +
  • Body Swap Test
  • Scroll Tests