Fix crash when an open :show page gets a PubSub broadcast for other items#6197
Conversation
|
Thank you! Sure feels like we should have caught that in review 😅 |
|
@josevalim should we have a separate topic that only broadcasts messages for a specific ID? |
|
The issue with doing it per ID is that we deliver double messages? Another option is to deal with updates only on the index page for the scaffold. |
|
How expensive if sending a PubSub message to a topic where nobody is subscribed? It's only the messages to the other nodes, right? Having update/delete broadcast to two topics is a pattern that I frequently used already. But the catch all might be just fine here? I think it depends on which way we want to push people towards. I think if we do PubSub, all pages should update, so I wouldn't exclude the show page. |
|
Yes, the issue is when you have multiple nodes, two messages across the nodes. The catch-all is fine here. :) |
|
Let's go with this one then :) Thank you @nshafer! |
|
No problem, thank you both. =) |
In the code generated with
mix phx.gen.live, in theshow.exfile, there are 2handle_info/2callbacks that are tightly bound to only match when the messages broadcast from the context are for the item they are currently showing. If the user has another tab open on a show page, and does anything from another tab, such as adding, deleting or updating a different item, the show LV will crash with a "no function claus matching" exception.This simply adds a fallback
handle_info/2handler that tightly matches all other expected messages due to theContext.subscribe_items/1call in the generatedmount/3, so that LV won't crash when it gets an unexpected message. However, if it gets a different message that is from something else that the user adds, then it will still crash so they know they need to handle that message shape.