Closed puruzio closed 4 months ago
The fix was moving phx-update="stream"
to the div containing:for
instead of the immediate parent div as the documentation led me to believe. I decided to reopen this issue in hopes that the documentation is improved to clarify it a bit more, so other people don't experience the same issue I've been pulling my hair about for so long. Thanks!
<div class="flex flex-col" id={"id-#{@note_id}"}>
<div **phx-update="stream"** :for={{id, author} <- @streams.authors} id={id} class="truncate text-base text-gray-900 dark:text-white">
<p><%= author.name %></p>
</div>
</div>
@puruzio i didn’t test it yet, but I’m pretty sure your actual issue is that you are not using the correct dom id:
id={"dom_id-#{idx}"}
Maybe the documentation is still not clear enough about this.
The fix was moving phx-update="stream" to the div containing:for instead of the immediate parent div as the documentation led me to believe.
This will probably break the second stream in weird ways.
Indeed, your example works as expected if you don't alter the IDs:
<li
:for={{idx, note} <- @streams.searched_notes}
class="py-2 sm:pb-2 mt-2 flex flex-col border border-t-1 border-r-0$
id={idx}
>
There will be a more prominent warning about this in the docs, after https://github.com/phoenixframework/phoenix_live_view/pull/3265 is merged.
Environment
Actual behavior
In the example app below, pressing the Update button appends data instead of replacing it. The output looks like this.
Expected behavior
I was expecting the output to look like the following:
Example app