-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Live removal of issue comments using htmx websocket #28958
base: main
Are you sure you want to change the base?
Conversation
I will wait with further development until #28880 has a final decision for now. Just wanted to do this POC to see and show the team if it could be used for the discussed realtime topics as well. |
Wouldn't we say htmx will be used on simple situation? I think this page is very complex. |
I agree with lunny, this is more complex than I imagined but hey, if it works that's awesome. Do we really have 2 way communication here though? Maybe SSE fits better for this use case |
This comment was marked as resolved.
This comment was marked as resolved.
We need a Websocket in any case as SSE is too limiting:
|
Is it fine to hook into |
I think it should be. You need to implemente a new notifier like notification. |
I had a look at different options, but let me explain why I finally decided to give htmx a try in this case. From the used frameworks I see 3 options how UI updates could be done in the frontend in general:
Sure this is currently the case, however this could be done as shown in #29719 by adding some pubsub interface that sends the updates from |
I'm convinced |
Needs a PS: I need to read through above but I'm generally okay with everything to finally get this websocket in so we can also start removing the |
And needs a |
This is not a high-efficiency implementation to iterate all the WebSocket sessions. Maybe the best way is to use Pubsub. So when a WebSocket client connects to the server, it will send his topic(maybe the URL could be the topic), when the client disconnects, the subscription should be removed. When an event is fired, the topic subscriters will receive the notifications. To implement that, I think maybe we can remove |
Sure, I can give it a try. When using the url as topic, I would need to publish to all urls a specific event could possibly be interesting for. So ie an issue name change would be interesting for the issue page, but also for the issue list page and the issue list page of an org, right? How should we implement the "rendering" part. As we want to send the template for the specific user connected (for example to show the issue comment author / owner badges) should I pass and use the user inside the subscription callback function and render the content in there? |
This will work for main thread websocket that reconnects on every page load, but once we move it to SharedWorker, it could be common that user has multiple tabs open and the SharedWorker would only disconnect when the last tab is closed. So for that scenario, a unsubscribe message would also needed. |
Maybe per-repo will be fine for a start, e.g. key |
BTW if we keep melody, we would likely need to increase it's |
Okay, I adjusted the code a bit so it sends messages through pubsub and to use subscriptions instead of the for loop iterating the sessions. I currently see two options how the initial notifier event could be brought to a websocket client. What do you think?
|
return | ||
} | ||
|
||
n.pubsub.Publish(ctx, pubsub.Message{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the topic should still contain the issue and index. And it also includes the actions like delete/create/update. Because I think different pages of the same clients should not share the same web socket client.
} | ||
|
||
ctx := goContext.Background() // TODO: use proper context | ||
h.pubsub.Subscribe(ctx, msgData.Repo, func(msg pubsub.Message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an anonymous user are staying on an issue view page, shouldn't the page will be automatically updated?
First step into "realtime" updating UI using htmx with ws extension as discussed in #2287 and #25661
As rendering comments was quite tough (a lot of code changes) I just implemented the updating UI part for removing a comment for now as a reference. All other events will be quite simple to add from now on and only require some rendering logic to be adjusted.
htxm logic based on #28908
websocket logic based on #26679 and #27806
Screencast.from.2024-02-16.17-50-20.webm
How it works:
/-/ws
dom.load
:{ action: "subscrib", data: { url: "http:https://localhost:3000/anbraten/test/issues/1"}}
to the server to let it know it is interested in updates relevant to this pageTODO