Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.9.10] WebSockets: handling events with hx-on seems broken #2131

Open
haja opened this issue Dec 26, 2023 · 0 comments
Open

[1.9.10] WebSockets: handling events with hx-on seems broken #2131

haja opened this issue Dec 26, 2023 · 0 comments

Comments

@haja
Copy link

haja commented Dec 26, 2023

Hi,

The behaviour of websocket-extension with hx-on is a bit counter-intuitive in my opinion.
Connecting and receiving updates via the websocket works flawlessly, but registering events via hx-on on a child element of the hs-ext="ws"-element does not seem to work:

<!-- not wokring -->
<div id="htmx-livedata" hx-ext="ws" ws-connect="/ws/client">
  <div hx-on:htmx:ws-connecting="console.log('websocket connecting', event)">
    event-holder
  </div>
</div>

The events are received via global handler, though, so this works as expected:

<!-- end of body, working example -->
<script>
document.body.addEventListener('htmx:ws-connecting', function (evt) {
    console.log(evt);
})
</script>

And registering on the ws element directly seems to work for consecutive connects, but not on the inital page laod:

<!-- this work on reconnects -->
<div hx-ext="ws" ws-connect="/ws/client" hx-on:htmx:ws-connecting="console.log('websocket connecting', event)">
  event-holder
</div>

Is this a known issue? I haven't found any hints on such limitation in the docs (neither hx-on nor ws-ext).

@haja haja changed the title WebSockets: handling events with hx-on seems broken [1.9.10] WebSockets: handling events with hx-on seems broken Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant