From aee1d0538c21e815f629d4d04c07d485040b8f39 Mon Sep 17 00:00:00 2001 From: MichaelWest22 Date: Fri, 16 Aug 2024 14:48:45 +1200 Subject: [PATCH] remove extra hx-swap-oob tag that is not used in the page --- src/htmx.js | 2 ++ test/attributes/hx-swap-oob.js | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index e7613d151..d74856875 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1426,6 +1426,8 @@ var htmx = (function() { } else { swapStyle = oobValue } + oobElement.removeAttribute('hx-swap-oob') + oobElement.removeAttribute('data-hx-swap-oob') const targets = getDocument().querySelectorAll(selector) if (targets) { diff --git a/test/attributes/hx-swap-oob.js b/test/attributes/hx-swap-oob.js index 7a2165be8..327d583da 100644 --- a/test/attributes/hx-swap-oob.js +++ b/test/attributes/hx-swap-oob.js @@ -66,6 +66,28 @@ describe('hx-swap-oob attribute', function() { }) } + it('handles remvoing hx-swap-oob tag', function() { + this.server.respondWith('GET', '/test', "Clicked
Swapped3
") + var div = make('
click me
') + make('
') + div.click() + this.server.respond() + div.innerHTML.should.equal('Clicked') + byId('d1').innerHTML.should.equal('Swapped3') + byId('d1').hasAttribute('hx-swap-oob').should.equal(false) + }) + + it('handles remvoing data-hx-swap-oob tag', function() { + this.server.respondWith('GET', '/test', "Clicked
Swapped3
") + var div = make('
click me
') + make('
') + div.click() + this.server.respond() + div.innerHTML.should.equal('Clicked') + byId('d1').innerHTML.should.equal('Swapped3') + byId('d1').hasAttribute('data-hx-swap-oob').should.equal(false) + }) + it('handles no id match properly', function() { this.server.respondWith('GET', '/test', "Clicked
Swapped2
") var div = make('
click me
') @@ -155,6 +177,7 @@ describe('hx-swap-oob attribute', function() { it('swaps into all targets that match the selector (outerHTML)', function() { var oobSwapContent = '
Swapped9
' + var finalContent = '
Swapped9
' this.server.respondWith('GET', '/test', '
Clicked
' + oobSwapContent) var div = make('
click me
') make('
No swap
') @@ -163,8 +186,8 @@ describe('hx-swap-oob attribute', function() { div.click() this.server.respond() byId('d1').innerHTML.should.equal('
No swap
') - byId('d2').innerHTML.should.equal(oobSwapContent) - byId('d3').innerHTML.should.equal(oobSwapContent) + byId('d2').innerHTML.should.equal(finalContent) + byId('d3').innerHTML.should.equal(finalContent) }) it('oob swap delete works properly', function() {