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

Turbo morph not preserving stimulus values #1210

Open
rbclark opened this issue Mar 1, 2024 · 1 comment
Open

Turbo morph not preserving stimulus values #1210

rbclark opened this issue Mar 1, 2024 · 1 comment

Comments

@rbclark
Copy link

rbclark commented Mar 1, 2024

I am unsure if this issue is with Stimulus or Turbo, so I apologize if this is the wrong repo. I am using Turbo 8 morphing and I am noticing that all my controller values are reset when my page morphs. This behavior is a bit confusing since the connect callback is also skipped in these situations. I've included a simple example repo I used for testing this behavior here: https://github.com/rbclark/turbo-8-stimulus-bug-demo

In the video below I initially load the page and then after the first refresh morph the connected-value attribute disappears.

Screen.Recording.2024-02-29.at.8.28.26.PM.mov

For now I have a global workaround added to my application.js to avoid this issue, although I'm not sure if it will have any other unforseen implications:

document.addEventListener("turbo:before-morph-attribute", (event) => {
  const {detail: {attributeName}} = event

  if (attributeName.startsWith("data-") && attributeName.endsWith("-value")) {
    event.preventDefault()
  }
})

With how well Stimulus works with Turbo normally, it would be great if this behavior just worked out of the box.

@seanpdoyle
Copy link
Contributor

Thank you for opening this issue and for sharing a reproduction repository.

This feels related to several existing issues:

The events that you mention were introduced by #1097 (as a successor to a commit (9944490) that was ultimately reverted).

although I'm not sure if it will have any other unforseen implications

The unforeseen circumstances are certainly a risk. Over-committing to ignore all server-sent Stimulus Values feels safer than under-committing. I'm sure with time there will be some edge cases that will emerge.

it would be great if this behavior just worked out of the box.

Integration with Stimulus was the main driver behind that contribution. As the dust of the Turbo 8 release settles, I hope that there will bandwidth for a coordinated effort to expand built-in Morph integration for Stimulus and Trix (and therefore Action Text). Something that affords a configuration-less turn-key solution for most circumstances with some focused escape hatches when necessary.

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

2 participants