Comments (6)
@rbclark That seems off to me because the refresh action which is broadcast is tied to a specific model and then views simply subscribe to refreshes from that model. The model does blind broadcasts_refreshes
and any pages which are subscribed to it refresh. It does not seem proper for the backend model to consider which particular frame to send a refresh to.
What happens now if you put a <%= turbo_stream_from :model %> inside a turbo frame and then have the backend do it's usual
broadcasts_refreshes`?
I know for sure that if the turbo_stream_from is outside of the turbo-frame, that will trigger a refreshing morph of the full page, which subsequently triggers a morphing refresh to each individual turbo-frame on the page (provided that those turbo frames have refresh=morph
. It sounds like this alone would get you what you want.
But it may be the case that if you put the turbo_stream_from inside of a turbo frame it might only refresh that frame, without having to do a special refresh broadcast which targets that frame. Give it a shot and see what happens. And if that doesn't work then maybe the base-case will still work for you to just trigger a refresh of the full page.
from turbo.
@krschacht Thank you for your reply! I appreciate your perspective on this, it seems I've used broadcast_replace_to(dom_id(...))
one too many times and seem to still be thinking in that paradigm. Putting a refresh inside a turbo frame makes a lot more sense. I tried out what you said, I placed a turbo_stream_from @model
and added broadcasts_refreshes
inside of that model inside of a turbo_frame
to test it out and unfortunately it just went ahead and triggered a full page morph instead of a targeted frame morph.
For the page in question, it already heavily utilizes turbo streams and stimulus controllers. I spent most of the week investigating converting it over to morphing and came to the conclusion that it would be a significant undertaking to get it all to morph properly since the page consists of filtering, sorting, cross-page-multi-select, and expandable sections each with their own trix editor. I'm also a bit worried about the performance of this page after a full morph since I had to apply a decent amount of logic in before-morph
actions to preserve existing state during my testing. Overall in my case I think there would be a lot less strange edge cases and an overall faster user experience in my application if I could easily trigger refreshes of compartmentalized frames.
from turbo.
Conceptually, the idea behind broadcast_refresh is "I don't want to think about what parts of the page need to be updated. Please update any parts of the page that ought to change now that I've made an update to this particular model." So the idea that it always triggers a full page morph feels appropriate. Because a full page morph may result in zero dom nodes being updates or lots of dom nodes updating.
I would be surprised that morphing would mess things up. Maybe you simply need to add some "permanent" tags in the right places.
But I'm still new to moprhing as well so I don't know all the edge cases with it. My app is pretty simple so far (https://github.com/the-dot-bot/hostedgpt)
from turbo.
Oh, but note that once The 1192 PR gets merged in you will be able to use javascript to target any individual turbo-frame you want and call a .refresh() on it. So it would be a bit hacky, but you could wire up your own special turbo stream action which exists solely to trigger the morphing refresh of specific turbo frames.
from turbo.
@krschacht I tried to document some of the gotcha’s that I think are bugs in a few of the issues I opened on this repository. A lot of the issues revolved around keeping stimulus state and things like that. There’s also some stuff that I want to be permanent in some situations and temporary in others, the app I’m working on has one very complex page in particular that is causing issues.
Regarding implementing a custom turbo action, that’s my plan next week. I just figured I’d float the idea to the project as a whole since I think it’ll be useful for people other than just me!
from turbo.
Related Issues (20)
- Event turbo:before-render is fired twice, unless caching is disabled. HOT 7
- Support `data-turbo-frame="_parent"` in nested frames
- Morphing is updates an `a` tag, but not it's content, but only on the client who initiated the action HOT 10
- Navigating to page with non-successful response seems to reload javascript HOT 9
- Turbo doesn't send Turbo-Frame header when frame's src is updated HOT 13
- Morphing: impossible to "clear" a form due to ignoreActiveValue: true HOT 9
- Morphing overwrites the user's input on active element HOT 4
- Turbo 8 link advance with frame and temporary not render
- Progress bar does not disappear after fast network response HOT 2
- Turbo 8 data-turbo-action=advance and turbo stream replaces head section HOT 2
- InstaClick does not work when use frame to same page
- Turbo stream refresh takes precedence over user interaction HOT 3
- Turbo morph not preserving stimulus values HOT 1
- Turbo morph displays progress bar HOT 2
- [QUESTION] Plans for turbo handle routes? HOT 1
- Using data-turbo-action="advance" to update URL breaks morphing
- turbo_frame_tag src: format: turbo_stream call back refresh morph.
- `turbo:before-fetch-response` not always fired on link HOT 1
- Make turbo progress bar optional HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbo.