-
Notifications
You must be signed in to change notification settings - Fork 433
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
Add morph
Turbo Stream Action
#1163
Comments
@danecando what would be an example use case for this? In my usage so far, you either use Turbo Stream -or- you morph. I can’t imagine using a stream to trigger a morph. When I’m doing a turbo stream, it’s because I’m updating the specific piece of the page that I care about. Are you using Turbo Stream for a large section? |
I think the use cases are probably less than I had suspected initially. Probably replacing larger chunks of content or things containing images to prevent additional requests or potential flashes |
I had a use case when I wanted to animate a list of item using https://auto-animate.formkit.com/ |
@adrienpoly Are you suggesting that there is already a turbo stream action for triggering a morph? Or do you mean that you chose to not use a turbo stream action and instead triggered a page refresh / morph of the whole page? |
Overall, I don’t think it’s right to conceive of morph as desired turbo stream action. I’d suggest we probably close this as an issue. Page Refresh w/ morph and Turbo Stream actions are really alternatives to each other. We are intended to pick one or the other. If you want to be surgical about your updates to the page, you wire up a bunch of Turbo Stream actions which makes just the right update/append/insert as needed. Or if that’s too much work, you can instead trigger a full Page Refresh and tell it to morph what it gets back. It’s a little heavier handed (e.g. two HTTP responses and a larger payload) but not too much so and it should just magically work. |
@krschacht no there is no official Morph but adding a custom action is fairly easy now. https://marcoroth.dev/posts/guide-to-custom-turbo-stream-actions. They are even a few packages to get it out of the box I was just giving a use case where Stream morph has been useful for me in the past. Maybe today I would build it with a full page morph 🤷♂️ |
@adrienpoly Ah, yes, that’s not crazy. I think this is a great example of why there i support for custom actions. I’d say: custom actions is the right “solution” the library provides for this need and adding it as an official turbo stream action wouldn’t be right. This is a case where the library making this “difficult” is a feature rather than a bug.:) |
There are definitely reasons why you'd want to have an independent morph action. Morphing has the benefit of not loosing client-side state. In any case where you are currently using But even if we don't add a |
Downside being the user would have to load the Idiomorph dependency twice since it's not exposed in the Turbo bundle - unless I'm mistaken? |
I'm working on a project where I'd to create a
I think idiomorph should be a peer-dependency or exposed so we can reuse it elsewhere. |
FWIW, we have a use case similar to @m4theushw and would make heavy use of turbo stream morphs. We use a lot of modals, especially on expensive pages, where the modal will load a lightweight form. When making selections in the form, we often want to re-render it, since certain selected fields might change other parts of the form. We don't want to reload the whole page, because the modal is sitting on top of an expensive page, and when a form changes, you want it to re-render as quickly as possible. Stimulus Reflex has a similar distinction, where you can do either a full page morph or a selector morph. But with that library, you can use either I recently spiked out adding |
I added a PR to address this. For me the main motivation is being able to morph a component/element on the page while preserving the state. That can be handy in so many use cases. |
@seanpdoyle I think this issue can be closed 🎉 |
@afcapel or @jorgemanrubia could either of you close this issue? |
Would be nice to support a
morph
turbo stream action for users who maybe aren't ready to opt in or transition to full page morphing.The text was updated successfully, but these errors were encountered: