didus
Temporary assigns with streams causes the order of items to be reversed when prepending
Hi,
We have a page where we display events to users that relies on infinte scrolling. We decided to migrate from the old phx-update and temprory assigns fashion to LV Streams to leverage the :reset option to be able to clear the page when user makes a search with no results and everything works fine. Howerver, we are facing a strange issue when prepending new events with the option at: 0 of the stream function. This causes the order of items to be reversed on the client side ! the DB request does its job well with the right sorting order so why this option is reversing the order ? is it the normal behavior ? note that we didn’t have this issue before (with phx-update="prepend") and as a workaround is to use Enum.reverse() function :
stream(socket, :events, Enum.reverse(new_events), at: 0)
Thanks for your help
Most Liked
sodapopcan
Streams have had a few problems which have been actively worked on recently. This should already be fixed in LiveView 0.20.4 which will be released soon. Try using main and see if you still have the issue.
Also, welcome!
steffend
Well it could be, but I’ve been discussing this with Chris and José and the decision was to document it. Internally this is implemented as a reduce calling stream_insert on the items, so the decision was between making a special case or just documenting it. You can add your arguments to the PR though. It’s not accepted yet ![]()







