bigskysoftware / htmx

</> htmx - high power tools for HTML
https://htmx.org
Other
37.14k stars 1.25k forks source link

Any plan to stabilize websockets? #702

Closed dkotrada closed 2 years ago

dkotrada commented 2 years ago

https://htmx.org/attributes/hx-ws/ about a year ago, I looked into reference. Websockets were marked as EXPERIMENTAL. Is there a roadmap to stabilize websockets in htmx?

benpate commented 2 years ago

YES! We've just finished a project to move WebSockets into their own extension, and should be the final home for this feature. It will require some minor updates to your existing code, but should function identically to the original attribute. The update is currently in the DEV branch, and is planned to be officially released with the next version of htmx (1.7)

If you're using WebSockets, I strongly suggest you check out the new code and weigh in on how it works.

1cg commented 2 years ago

Yes, both web sockets and sse are being stabilized. The good news is that the current API will likely be supported in perpetuity so you can work with it today and be reasonably certain you won't need to make many code changes going forward.

rajasimon commented 2 years ago

@benpate Where I can find the websocket extension? Is that code in public?

I connected the hx-ws but the thing is Django channels returns json response so I don't see any swap in the template. I thought I can create the extension for capturing the ws response and convert to html so that htmx swap it for me but I'm wrong. Help me out here please.

benpate commented 2 years ago

It's currently in the DEV branch. However, we've been reviewing the change and we think we can do better. The current approach as an extension will require a small change to the syntax that you use (from hx-ws="" to hx-ext="ws" ws-connect=""). Though we this change would be worth the benefit, we're going to try updating the extensions so that they can use the existing hx-ws syntax.

So, please check out (and contribute to!) the work we're doing, but don't go switching your apps around just yet -- we're going to try to preserve backwards compatibility. Does this make sense?

rajasimon commented 2 years ago

@benpate Thanks for your response. I tried loading that extension in my local but somehow I get undefined error. I know that it's in the early stage development so thought this traceback help in the development.

<div hx-ext="ws" ws-connect="ws/chat/{{ request.user }}/ ">
    <div id="chat_room">
        resting
    </div>
</div>
TypeError: undefined is not an object (evaluating 'api.hasAttribute')
queryAttributeOnThisOrChildren — localhost:2277
onEvent — localhost:2091
(anonymous function) — htmx.min.js:1:19954
(anonymous function) — htmx.min.js:1:19547
B — htmx.min.js:1:3283
st — htmx.min.js:1:19523
lt — htmx.min.js:1:19925
tt — htmx.min.js:1:19025
(anonymous function) — htmx.min.js:1:19104
B — htmx.min.js:1:3283
rt — htmx.min.js:1:19083
(anonymous function) — htmx.min.js:1:34753