Postponed
See #3393105: Hotwire Turbo minimum viable implementation for more information. We may implement this at a later date but it's out of scope for the time being.
Problem/Motivation
References:
- Main Symfony UX repo
- Symfony version of Turbo
- Symfony UX Turbo documentation - this has a lot of details of how to integrate it into a PHP app.
The links above show an overview of what Symfony UX is trying to accomplish as well as the "Hotwire Turbo integration for Symfony" which relates to this project. This issue was created to gauge interest in working to use as much Symfony UX Turbo as possible and see what contributors to this project have to say about the idea.
I believe work in the "ux-turbo" repo can be incorporated into this project, specifically the TurboStreamResponse class and integration into the router component.
Proposed resolution
I'm not far into investigating how this module can be updated to integrate with what Symfony is doing, but I wanted to see if others had feedback as well as have someplace where potential collaboration can be had between Drupal and Symfony communities.
Changes I know so far that have to be made:
- All JS needs to be loaded in
<head>and not the end of<body>. An initial solution might be to move thejs-bottomto the placeholder for thehead-js. - BigPipe - I'm not sure where Drupal is at with BigPipe and if it played out as people wanted. But I imagine the placeholder tags would interfere with registering Stimulus controllers and attaching them to events.
Drupal.behaviors"attach" needs to fire on turbo events. There are no page refreshes so looking for aloadevent won't work. It's more an event liketurbo:loadthat needs to be listened to.Drupal.behaviorswould be converted to use Stimulus controllers.TurboStreamResponsehas to be implemented in some way for turbo streams to work properly. Hopefully using Symfony components for routing in Drupal helps make this addition easier.- Integrate the Entrypoints module or some other way to load bundled CSS/JS. I'm not sure if Webpack Encore will continue or they will move to an unbundled "import map" approach like in Rails 7...but if more Encore features can be utilized then it takes more maintenance burden off of Drupal's contributors.
- A theme with templates for Turbo needs to be created and linked with this project. Symfony UX uses Twig also, so once again, hopefully, the templating work is made easier by re-using what Symfony is already developing.
That's about all I can think of for now. I really like the idea and experience of Refreshless, and I hope enough people are interested in the Drupal world to provide a coupled, monolithic version of Drupal that still feels like a SPA done with JS...then the people with large budgets and many devs can take the decoupled approach. However, every Drupal project I've worked on (in small teams, mainly) would benefit more from Turbo than Decoupled Drupal.
Remaining tasks
TBD
User interface changes
TBD
API changes
TBD
Data model changes
TBD
Comments
Comment #2
ambient.impactI'm very interested in helping out with this effort. I see Turbo as incredibly powerful and a great argument that progressive enhancement and a modern, app-like feel are completely compatible.
I think starting with a barebones minimum viable implementation is the way to go, and then build on that with the additional points listed. Some initial thoughts:
Comment #3
ambient.impactFixed and improved some code formatting in the summary for you. ;)
Comment #4
ambient.impactComment #5
ambient.impactAdded link to Symfony UX Turbo documentation.
Comment #6
ambient.impactComment #7
wim leersThank you so much for taking the time to do this write-up, @afinnarn, and for refining it, @Ambient.Impact! 🤩 👏
Hesitation
I am hesitant/concerned about adopting https://turbo.hotwired.dev/ because of the big notice you can see at the top of https://www.drupal.org/project/turbolinks
They were very aggressive about it.
Then again … https://github.com/symfony/ux-turbo seems to have been around for a while and they somehow did not get shouted at by the creators of Turbolinks? 🙃🤷
Technically
Technically speaking, I'm not at all opposed to reusing a Symfony component! 😄
+1 for @Ambient.Impact's proposal to (at least initially) require BigPipe to be disabled.
This sounds like it would be impossible to make it work automatically for contrib/custom modules'
Drupal.behaviors? 😅😱 Sounds like @Ambient.Impact has similar concerns.We'd need to figure out a way to make this work transparently, otherwise this seems not viable. (I did not look into what "Stimulus controllers" are.)
Similar concerns apply to the loading of additional CSS/JS.
Conclusion
Big +1 for creating a new branch of Refreshless that adopts this! But prior to building it all, I think we should prototype the foundations to ensure it can work as early as possible, without spending weeks/months on building this. Happy to provide reviews 😊
Comment #8
wim leersOMG, it looks like this prototype now already exists!?
Comment #9
sebastix@WimLeers
@Ambient.Impact showed me a video of the prototype through Mastodon a while ago, but I can't find it anymore.
Comment #10
wim leersI watched presumably the same video in in a Drupal Slack DM earlier today.
The next step here is to i) review, ii) manually test #3393105: Hotwire Turbo minimum viable implementation. You could help with that, @Sebastian Hagens 😄
Comment #11
ambient.impact@Wim Leers
For what it's worth, I read through the exchange you had with them and was appalled at how they treated you. Sure, there's some reasonable discussion they could have had about naming and branding, but they threw that out the window.
It's probably because they use the official Turbo that it's technically okay with them. I think as long as we don't use the Turbo name other than to refer to our own integration with the official Turbo library/framework we should be following their requirements, even if we feel they're overly restrictive/stringent.
Yeah, I can't really see an easy way to do this automagically that won't break some contrib code. It'd be interesting to explore at some point, but it feels like a whole project in itself. Also, controllers in Stimulus are just JavaScript classes that get automatically attached and detached to various elements. There's a bunch of other stuff that I'm glossing over, but that's how I understand them.
😎
@Sebastian Hagens
Just uploaded it now to YouTube: https://www.youtube.com/watch?v=KYd7vQZRqMo
Comment #12
ambient.impactSee #3393105: Hotwire Turbo minimum viable implementation for more information.