I am doing an “infinite scroll” sort of page where the user can load more elements into a list. On the page, there is an element that holds the last item ID on list so that when an update is request, Rails can determine which item will be the next one in the sequence that should be returned. Of course, when the new data is appended to the list, that last item ID needs to be updated for the next possible request.
I was looking into whether I can send back two pieces of data for every Turbo stream request:
- The Turbo stream append operation to add the new items to the list
- A Turbo stream replace operation to update the placeholder for the last item on the list
I found the following Github post where DHH seems to suggest doing multiple updates via Turbo stream is a discouraged practice. However, I was unclear whether he was referring to the OP’s syntax suggestion or the general concept of performing multiple Turbo stream operations in a single response.
Could you please provide better guidance on the best practice where you might want to do more than one thing in a Turbo response? Like deleting some items while adding others? Or, is this a case where the aid of Stimulus is the best option?