DJE-012
Warning
Performance
Broadcast storm from push_to_view per keystroke
Error message
Application becomes unresponsive with multiple connected clients
Calling push_to_view() on every keystroke (e.g., in a collaborative editor) causes N full re-renders for N connected clients on every key press. This creates a broadcast storm that overwhelms both the server and connected browsers.
broadcast
bug-fixed
performance
websocket
Affected versions: >=0.2.0
Solution
Before (problematic)
class NoteEditor(LiveView):
def handle_event(self, event, params):
if event == "update_content":
self.content = params["content"]
# BAD: Broadcasts full re-render to ALL clients
self.push_to_view("note_channel")
After (fixed)
class NoteEditor(LiveView):
_skip_broadcast = False
def handle_event(self, event, params):
if event == "update_content":
self.content = params["content"]
self._skip_broadcast = True
self._broadcast("note_channel", {
"content": self.content
})
def _on_broadcast(self, channel, data):
self.content = data["content"]