Fix WebSocket extension trigger handlers initialization (#1468)

* fix websockets initialization to accomodate "haked hx-trigger"

* update changelog
This commit is contained in:
Denis Palashevskii 2023-06-08 01:04:40 +04:00 committed by GitHub
parent 81ead8e39a
commit 108d2b458a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,8 @@
# Changelog # Changelog
## [1.9.3] - 2023-04-28 ## [1.9.3] - 2023-06-??
* Fixed bug w/ WebSocket extension initilization caused by "naked" `hx-trigger` feature
## [1.9.2] - 2023-04-28 ## [1.9.2] - 2023-04-28

View File

@ -52,7 +52,7 @@ This extension adds support for WebSockets to htmx. See /www/extensions/ws.md f
return; return;
// Try to create websockets when elements are processed // Try to create websockets when elements are processed
case "htmx:afterProcessNode": case "htmx:beforeProcessNode":
var parent = evt.target; var parent = evt.target;
forEach(queryAttributeOnThisOrChildren(parent, "ws-connect"), function (child) { forEach(queryAttributeOnThisOrChildren(parent, "ws-connect"), function (child) {

View File

@ -77,6 +77,17 @@ describe("web-sockets extension", function () {
this.messages.length.should.equal(1); this.messages.length.should.equal(1);
}) })
it('sends data to the server with specific trigger', function () {
var div = make('<div hx-ext="ws" ws-connect="ws://localhost:8080"><div hx-trigger="click" ws-send id="d1">div1</div></div>');
this.tickMock();
byId("d1").click();
this.tickMock();
this.messages.length.should.equal(1);
})
it('handles message from the server', function () { it('handles message from the server', function () {
var div = make('<div hx-ext="ws" ws-connect="ws://localhost:8080"><div id="d1">div1</div><div id="d2">div2</div></div>'); var div = make('<div hx-ext="ws" ws-connect="ws://localhost:8080"><div id="d1">div1</div><div id="d2">div2</div></div>');
this.tickMock(); this.tickMock();