Skip to content
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

[Proposal] turbo-stream action 'versioning' #906

Open
mbell697 opened this issue Apr 14, 2023 · 2 comments
Open

[Proposal] turbo-stream action 'versioning' #906

mbell697 opened this issue Apr 14, 2023 · 2 comments

Comments

@mbell697
Copy link

mbell697 commented Apr 14, 2023

I'm using turbo-streams for a project and have noticed that in certain circumstances stream actions can be delivered out of order, an older update arriving after a newer update.

A concrete example would be replying from a rails controller directly with a turbo-stream action, but there also being a background job enqueued during that request that sends turbo-stream actions over actioncable. We've see the update from the background job arrive first with fresher data, only to have the controller turbo stream then arrive later replacing the dom content with stale data.

I think it would be a great feature to be able to provide an ordering key (version) along with the each action and have the update code reject the update if the value currently in the dom is smaller.

For example, if this sequence of actions arrived in the browser in this order:

<turbo-stream action="append" target="item" version="1"></turbo-stream>
<turbo-stream action="replace" target="item" version="3"></turbo-stream>
<turbo-stream action="replace" target="item" version="2"></turbo-stream>

The final action with version 2 would be rejected because 3 is the current version in the dom.

In practical applications, version would often be an updated_at timestamp.

I think this feature could be implemented with a simple stimulus controller for my particular situation, but I suspect it's common enough to belong in turbo-stream.

If interested in this feature - I'm happy to open a PR for it.

@phylor
Copy link

phylor commented Sep 3, 2024

@brunoprietog Is there any plan to include versioning in turbo stream actions, to avoid out-of-order updates? In my experience, running stale actions happens more often than one might think. It's especially noticeable when implementing progress updates, as the "finished" message might arrive before the last "loading" message, thus not updating correctly. Having a versioning builtin would be awesome!

@dhh
Copy link
Member

dhh commented Sep 15, 2024

I like this idea. Please do explore an implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants