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

[WIP] Stream Versioning #1324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mbell697
Copy link

@mbell697 mbell697 commented Oct 9, 2024

This still needs some additional more tests and docs prior to merging but I wanted to open this for comment on the general approach.

This is a proposed solution for #906

This PR introduces the concept of versioning for Turbo stream update and replace actions, see the above issue for more background.

Functionality:

  • Add the attribute data-steam-version on stream target element.
  • Add the attribute version on the turbo-stream element.
  • During update and replace: If versions are present, they are parsed as numeric values and compared, actions are rejected unless the new version is greater than the existing version.

The current API presented here does not attempt to automatically manage the versions within template content, i.e. an update looks like this:

<turbo-stream action="update" target="item" version="1">
  <template>
    <div id="item" data-turbo-version="1"></div>
  </template>
</turbo-stream>

Versioning information ends up duplicated both in the turbo-stream and the template content.

In theory we could search the template content for the target selector and propagate the version down from the turbo-stream element. But I think this is "too smart" and likely to have edge cases. I suspect most usage of turbo is via higher level libraries, like turbo-rails, and I think those layers should be able to mask the duplication given more domain knowledge.

Let me know what ya think and I'll wrap this up.

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

Successfully merging this pull request may close these issues.

1 participant