Fix loading-states event subscription to prevent saving loading states in history (#1116)

This commit is contained in:
Denis Palashevskii 2022-11-09 21:32:45 +04:00 committed by GitHub
parent 550e82e482
commit c87dc8a519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -169,7 +169,7 @@
)
}
if (name === 'htmx:afterOnLoad') {
if (name === 'htmx:beforeOnLoad') {
while (loadingStatesUndoQueue.length > 0) {
loadingStatesUndoQueue.shift()()
}

View File

@ -1,4 +1,4 @@
describe("loading states extension", function() {
describe("loading states extension", function () {
beforeEach(function () {
this.server = makeServer();
this.clock = sinon.useFakeTimers();
@ -140,4 +140,28 @@ describe("loading states extension", function() {
btn.getElementsByTagName("button")[0].innerHTML.should.equal("Clicked!");
});
it('history restore should not have loading states in content', function () {
// this test is based on test from test/attributes/hx-push-url.js:65
this.server.respondWith("GET", "/test1", '<button id="d2" hx-push-url="true" hx-get="/test2" hx-swap="outerHTML settle:0" data-loading-disable>test1</button>');
this.server.respondWith("GET", "/test2", '<button id="d3" hx-push-url="true" hx-get="/test3" hx-swap="outerHTML settle:0" data-loading-disable>test2</button>');
make('<div hx-ext="loading-states"><button id="d1" hx-push-url="true" hx-get="/test1" hx-swap="outerHTML settle:0" data-loading-disable>init</button></div>');
byId("d1").click();
byId("d1").disabled.should.be.true;
this.server.respond();
byId("d2").disabled.should.be.false;
var workArea = getWorkArea();
workArea.textContent.should.equal("test1");
byId("d2").click();
byId("d2").disabled.should.be.true;
this.server.respond();
workArea.textContent.should.equal("test2")
htmx._('restoreHistory')("/test1")
var el = byId("d2");
el.disabled.should.be.false;
})
});