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
FIX remove existing items in stream if reset=true #2864
Conversation
Thanks @micdahl for tackling this issue. Unfortunately, it does not seem to fix the bug described in #2826 I upgraded my repo (https://github.com/Malian/stream_reset_bug/tree/fix-micdahl) with your branch, and the behaviour is still the same. |
Hey @Malian, it seems that the javascript file which contains the change ( |
Hi again @Malian . I found out, how to get it running! From your phoenix app's folder:
After that you can start the phx.server and see the magic happen! If I understand it right, the build step is done by the maintainers of this repository if the pull request is accepted. So this is only neccessary until then. |
Thank you for the PR, @micdahl! I believe we don't want to remove them either, because that would rebuild all phx-hook entries inside. So we need a way to force a new ordering without deleting. |
Hi @josevalim and thank you for the feedback. I have just started working with live view, so I am not into the details. I am just wondering why rebuilding would be a problem when |
Does not seem to fix #2816 (which is about the test client). |
We can apply the right sorting by explicitly setting the if opts[:reset] do
new_socket = update_stream(socket, name, &LiveStream.reset(&1))
items
|> Enum.with_index()
|> Enum.reduce(new_socket, fn {item, i}, acc -> stream_insert(acc, name, item, Keyword.put(opts, :at, i)) end)
else
Enum.reduce(items, socket, fn item, acc -> stream_insert(acc, name, item, opts) end)
end or alternatively if opts[:reset] do
new_socket = update_stream(socket, name, &LiveStream.reset(&1))
items
|> Enum.reverse()
|> Enum.reduce(new_socket, fn item, acc -> stream_insert(acc, name, item, Keyword.put(opts, :at, 0)) end)
else
Enum.reduce(items, socket, fn item, acc -> stream_insert(acc, name, item, opts) end)
end I don't know if it is preferable to use I tested both locally and they work, I would be happy to open a PR for this. Edit: |
When using
stream(socket, :elements, elements, reset: true)
, elements that allready existed in the stream were not deleted from the DOM before the new elements are inserted. If the elements have a different order than before, this ordering was not mapped to the DOM.By removing the filter for already existing elements to delete them all, the given order of the elements is retained.
Fixes #2767, fixes #2826