danjac / chatter

POC chat application using Django and Stimulus
Other
3 stars 1 forks source link

make a new message doesn't refresh the message window #2

Open julzhk opened 3 years ago

julzhk commented 3 years ago

Not a show stopper & I know this is just a demo, but new messages don't appear in the message screen until there's a page refresh. When I understand how it all works I'll take a go at fixing it myself! :-)

thanks for the demo!

danjac commented 3 years ago

I'd also note that this is some months old and the frontend dependencies are out of date (turbo is now beta 4, for example). So it would be worth updating these as a starting point.

I have a separate library for handling turbo streams/frames:

https://github.com/hotwire-django/django-turbo-response

This again is up to date and is used in production, so related turbo stream handling code could also be replaced. While updating dependencies may or may not fix the issue (it could be just an unrelated bug) it would at least be easier to work with an up-to-date codebase.

danjac commented 3 years ago

One further thing (should be documented, I think): the socket URL is initiated with the site domain name (chat/room.html):

{% if page_obj.number == 1 %}
<div data-controller="chat"
     data-chat-socket-url-value="ws://{{ request.site.domain }}/ws/chat/"
     data-chat-send-url-value="{% url 'chat:send_message' room.id %}">

You should ensure the default Site instance domain is set to "localhost".