Skip to content

Commit 0e1eeec

Browse files
remove extra hx-swap-oob attribute that is not used in the page (#2823)
remove extra hx-swap-oob tag that is not used in the page
1 parent b23b2f0 commit 0e1eeec

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/htmx.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,8 @@ var htmx = (function() {
14191419
} else {
14201420
swapStyle = oobValue
14211421
}
1422+
oobElement.removeAttribute('hx-swap-oob')
1423+
oobElement.removeAttribute('data-hx-swap-oob')
14221424

14231425
const targets = getDocument().querySelectorAll(selector)
14241426
if (targets) {

test/attributes/hx-swap-oob.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ describe('hx-swap-oob attribute', function() {
6666
})
6767
}
6868

69+
it('handles remvoing hx-swap-oob tag', function() {
70+
this.server.respondWith('GET', '/test', "Clicked<div id='d1' data-hx-swap-oob='true'>Swapped3</div>")
71+
var div = make('<div data-hx-get="/test">click me</div>')
72+
make('<div id="d1"></div>')
73+
div.click()
74+
this.server.respond()
75+
div.innerHTML.should.equal('Clicked')
76+
byId('d1').innerHTML.should.equal('Swapped3')
77+
byId('d1').hasAttribute('hx-swap-oob').should.equal(false)
78+
})
79+
80+
it('handles remvoing data-hx-swap-oob tag', function() {
81+
this.server.respondWith('GET', '/test', "Clicked<div id='d1' data-hx-swap-oob='true'>Swapped3</div>")
82+
var div = make('<div data-hx-get="/test">click me</div>')
83+
make('<div id="d1"></div>')
84+
div.click()
85+
this.server.respond()
86+
div.innerHTML.should.equal('Clicked')
87+
byId('d1').innerHTML.should.equal('Swapped3')
88+
byId('d1').hasAttribute('data-hx-swap-oob').should.equal(false)
89+
})
90+
6991
it('handles no id match properly', function() {
7092
this.server.respondWith('GET', '/test', "Clicked<div id='d1' hx-swap-oob='true'>Swapped2</div>")
7193
var div = make('<div hx-get="/test">click me</div>')
@@ -155,6 +177,7 @@ describe('hx-swap-oob attribute', function() {
155177

156178
it('swaps into all targets that match the selector (outerHTML)', function() {
157179
var oobSwapContent = '<div class="new-target" hx-swap-oob="outerHTML:.target">Swapped9</div>'
180+
var finalContent = '<div class="new-target">Swapped9</div>'
158181
this.server.respondWith('GET', '/test', '<div>Clicked</div>' + oobSwapContent)
159182
var div = make('<div hx-get="/test">click me</div>')
160183
make('<div id="d1"><div>No swap</div></div>')
@@ -163,8 +186,8 @@ describe('hx-swap-oob attribute', function() {
163186
div.click()
164187
this.server.respond()
165188
byId('d1').innerHTML.should.equal('<div>No swap</div>')
166-
byId('d2').innerHTML.should.equal(oobSwapContent)
167-
byId('d3').innerHTML.should.equal(oobSwapContent)
189+
byId('d2').innerHTML.should.equal(finalContent)
190+
byId('d3').innerHTML.should.equal(finalContent)
168191
})
169192

170193
it('oob swap delete works properly', function() {

0 commit comments

Comments
 (0)