Stimulus.js
The Future of Rails as a Full-Stack Framework powered by Hotwire

Summarized using AI

The Future of Rails as a Full-Stack Framework powered by Hotwire

Marco Roth • October 05, 2023 • Amsterdam, Netherlands

In the video titled 'The Future of Rails as a Full-Stack Framework powered by Hotwire', Marco Roth discusses the transformative potential of the Hotwire ecosystem within Ruby on Rails. He emphasizes the importance of simplicity and productivity in software development, highlighting his personal journey from struggling with JavaScript to becoming an advocate for Hotwire. Roth explores the evolution of Rails, particularly the introduction of Hotwire and its core components, such as Turbo and Stimulus. He discusses the historical context of the project, tracing back its origins to Turbolinks in 2012 and the subsequent developments that led to the robust frameworks available today.

Key Points Discussed:
- Personal Journey: Roth shares his initial struggles with JavaScript and how a talk on Turbolinks profoundly influenced his development philosophy and led to his involvement in the Hotwire ecosystem.
- Hotwire Overview: The session highlights how Hotwire simplifies building interactive web applications by minimizing custom JavaScript needs, allowing developers to focus more on backend logic.
- Framework Evolution: Roth traces the history of Hotwire components like Turbolinks, Stimulus, and the release of Turbo in 2020, culminating in Rails 7 integrating Hotwire by default.
- Backend Focus: Emphasizing a 'single source of truth' for the application state, Roth argues that Hotwire promotes best practices by avoiding duplication of code across frontend and backend.
- Ecosystem Discussion: The speaker outlines essential elements of a great development ecosystem, including frameworks, community collaboration, and solid documentation, stressing the importance of maintaining a vibrant developer experience.
- Advancements in Turbo: Roth introduces new features in Turbo, including the view transitions API and Turbo Streams, and talks about how these developments enhance the usability of Hotwire.
- Future Directions: The session concludes with insights on ongoing developments like Turbo Boost and the need for continuous updates to support evolving application needs.

Roth's presentation is both an homage to the Ruby community and a call to action for developers to embrace simplicity and collaboration in building applications. He encourages a future where Hotwire maximizes its potential within the Ruby on Rails ecosystem, thanking the community for its contributions and support.

The Future of Rails as a Full-Stack Framework powered by Hotwire
Marco Roth • October 05, 2023 • Amsterdam, Netherlands

Hotwire has revolutionized the way we build interactive web applications using Ruby on Rails. In this talk, Marco Roth, the maintainer of Stimulus, StimulusReflex and CableReady, takes an in-depth look at the recent advancements in Hotwire and shares guidance on how to effectively utilize Stimulus, Turbo, and other related frameworks.

Slides available at: https://speakerdeck.com/marcoroth/the-future-of-rails-as-a-full-stack-framework-powered-by-hotwire

Links:
https://rubyonrails.org/
https://hotwired.dev/
https://hotwire.io/
https://github.com/marcoroth/hotwire.io

#RailsWorld #RubyonRails #Hotwire #Turbo #Stimulus #Fullstack

Rails World 2023

00:00:15.679 Hello! I'm super excited to be here. If you haven't met me yet, I would love to meet you, so please come and say hi after the talk. I'm very thankful for this opportunity to have an in-person conference again.
00:00:28.800 I love to see this and actually give my first talk at a conference in this kind of fashion. This is super awesome for me.
00:00:34.160 This session is about the exciting future of the Hotwire ecosystem and its potential. I think we have some really cool things to cover today.
00:00:40.719 But before we start, can I get a quick show of hands? How many of you have heard about Hotwire? This seems to be the whole room, which is awesome! And how many of you are using it in production today? Okay, about half. I think we can do better, but this is already great.
00:00:59.440 I'm here today because I love Ruby, I love Rails, and I love this community. Rails has changed quite a bit over the years, but in essence, the principles have stayed the same since I first discovered Ruby in 2012 and have been enjoying it ever since.
00:01:19.520 I really appreciate the love of the language and the syntax it provides to build applications with expressive and simple syntax. Now, why should I stick with Ruby and not choose any of the shiny frameworks out there? It's simple: Ruby makes me happy, and it makes me as a programmer really productive.
00:01:31.040 I've written a lot of code in various languages, but nothing really comes close to Ruby in that regard. When I started with web development, I really struggled with JavaScript at first, and I think some of you probably did as well.
00:01:45.360 I was more than thankful for jQuery back at the time, which helped me stay sane and implement some features. But in the meantime, the web has changed quite a bit. JavaScript has evolved, new standards have emerged, and the browser landscape has greatly improved.
00:02:06.799 Yes, I'm looking at you, Internet Explorer. The trend in the industry has been to move a lot of this code to the frontend as React and friends became mainstream and changed the scene drastically for the better.
00:02:31.840 Personally, I quite like React; I think in its simplest form it's really great and something some teams might be able to use. However, there are also a lot of complicated things about React, and I believe we can do better than that. The complexity is often not worth it.
00:02:56.440 In 2016, I came across a talk by Sam Stevenson, who was speaking at RailsConf about Turbolinks 5 and its new features. I would say this talk single-handedly changed my view on how I see the web and how I want to architect my applications going forward.
00:03:39.560 Personally, I've been quite impressed by Ruby and the Rails way ever since. However, Sam's talk really influenced how I wanted to see and build my web applications. I appreciate he shared the HTML over the wire approach and the mindset behind it.
00:04:06.439 I feel lucky to have come across this talk because otherwise, I probably wouldn't be here today. If you haven't seen this talk, I encourage you to check it out; it's still applicable today with all the modern features we have in Hotwire.
00:04:30.400 In 2019, after getting frustrated by many over-engineered React applications I was working on, I wanted to help improve the state of reactive applications in Rails, which is also why I started contributing to open source.
00:05:19.680 I aimed to build an ecosystem for reactive applications that was aligned with how I wanted to develop my own applications.
00:05:29.560 Here are some of the projects I've contributed to. I've been a team member of the Stimulus, StimulusReflex, and CableReady projects for almost four years and have been maintaining the popular Stimulus library for the last two years.
00:05:48.360 Today, I would like to talk about the future of Hotwire and how we got to where we are today. React and its ecosystem are popular choices for most companies, even if they are just exposing an API for the frontend. However, with the release of Rails 7, things started to change quite a bit.
00:06:44.000 Combining Rails with Hotwire generated a lot of enthusiasm among users. Personally, I believe that Rails apps are the best way to build web applications, and the service-oriented architecture provides a much simpler way to build apps.
00:07:12.799 I'm sure most people in this room would agree. Let’s see how we got here.
00:07:18.360 Turbolinks was first released in 2012 and shipped a year later in 2013 with Rails 4. The launch of Turbolinks marked the journey of what we today know as Hotwire. Turbolinks 5 followed in 2016 as part of the major Rails 5 release, which also included support for WebSockets with Action Cable.
00:07:43.440 In 2017, ActionCableReady was released, and in 2018, Phoenix LiveView emerged in the Phoenix community, alongside StimulusReflex. StimulusReflex is inspired by that library and aims to provide an abstraction layer for building reactive applications in Rails.
00:08:00.720 In late 2020, Turbo and the Hotwire umbrella were released, giving a formal name to this approach we now call Hotwire. In late 2021, Rails 7 was released, which shipped Hotwire by default.
00:09:04.800 To conclude, the Hotwire approach isn't entirely new. If you look at the history, it's quite old. Many concepts were present even in 2017 with Turbolinks and Stimulus, with some new ideas introduced that helped shape how we write Turbo applications today.
00:09:55.360 One of the reasons I appreciate the Hotwire approach is that it provides a single source of truth on the backend. We don’t need to duplicate code on the frontend to create beautiful interfaces. I enjoy making pretty user interfaces, but I don't want to spend my whole day figuring out how to implement this in React.
00:10:51.680 Everything stays where it belongs, which leads to a common misconception about Hotwire. It's not about eliminating JavaScript from your applications, but rather minimizing how much you need to write yourself.
00:11:54.560 Today, any application needs JavaScript, whether we like it or not. We still have to rely on it to build modern applications.
00:12:00.000 I believe Hotwire abstracts this well with Stimulus and all the related libraries. With that said, I want to take a moment to discuss what makes a great ecosystem.
00:12:49.440 In my opinion, a great ecosystem is more than just technologies and frameworks. It's a combination of key ingredients that come together to create something truly special.
00:13:10.960 This combination includes frameworks, tools, documentation, and community efforts that work seamlessly together to create a unique and meaningful experience for all of us.
00:14:01.680 A rich set of libraries helps empower developers to create amazing applications—whether they prefer to write minimal JavaScript or build ambitious projects with Rails and JavaScript. We need to ensure that we have the resources to use those libraries.
00:14:45.319 To build a great ecosystem, we require a few well-thought-out building blocks that are pluggable, composable, and interchangeable. This allows us to select the appropriate tools for our applications.
00:15:26.560 Rails embodies these qualities, and I think the same should apply to Hotwire. Lastly, I think community plays a significant part in this.
00:16:06.160 As a community, we can build greater and more impactful projects compared to the independent work seen in other frameworks.
00:16:38.000 Let's talk about frameworks. I'm sure you’re all familiar with the many frameworks available today, especially the popular ones. However, I want to highlight some features and new additions to Turbo that we saw this morning, specifically the view transitions API and morphing additions.
00:17:30.960 These additions to Turbo are excellent examples of adopting and building new features based on modern JavaScript APIs. I would love to see more advancements in this direction.
00:18:05.440 Another great development is the reduction of libraries that now have built-in features in Turbo. Many libraries that offered similar functionality a few years ago, including morphing features, can now be found integrated within Turbo.
00:19:12.680 Now let's discuss other tools we can use to build modern applications. There's a library called Stimulus Use, which provides a composable way of adding mixins to your Stimulus controllers, simplifying controller usage.
00:20:06.640 I would argue that you could consider this the standard library for Stimulus, as it greatly simplifies many common use cases.
00:20:45.680 For example, we can use the useWindowsResize function from Stimulus Use in our controller's connect method. This will log out the window's width and height whenever the window is resized.
00:21:14.320 This demonstrates that we can write JavaScript like this while fully embracing the Hotwire way. There’s a lot of functionality covered by Stimulus Use. If you don't know much about it, I encourage you to check it out—it’s great for simplifying many common use cases.
00:21:56.080 Now let's talk about Turbo Streams. If you've been using Turbo Streams, you're likely familiar with the seven default actions that ship with Turbo.
00:22:05.680 With Turbo 7.2, we gained the ability to write our own custom stream actions, which opens up possibilities for more advanced use cases.
00:22:37.840 Earlier, I talked about CableReady, which conceptually is similar to Turbo Streams. The main difference is that CableReady uses JSON for payloads while Turbo Streams use HTML.
00:23:08.119 CableReady comes with around 40 different actions, while Turbo Streams have only seven. This motivated me to build a library called Turbo Power, which adds additional stream actions to Turbo Streams.
00:23:50.919 There are more functionalities to be added in Turbo Power. However, many of the advanced use cases that Turbo performs can be addressed by additional actions provided by Turbo Power.
00:24:27.679 Now you might wonder if these two libraries still exist, and why we would want to keep using them. The truth is that as Turbo becomes more capable, we want to ensure that some of the concepts and features from both libraries can still be useful.
00:25:17.519 One of the core principles of Stimulus Reflex focuses on building reactive applications using the Rails tooling you already know and love. This included utilizing Turbolinks and Stimulus back in 2017.
00:25:52.680 As you likely know, many developments have transpired in the meantime. We aimed to enhance the Hotwire ecosystem to cover the overlap and ensure that we don't need two separate ecosystems based on the same libraries.
00:26:24.480 This led us to port several unique Stimulus Reflex functionalities over to Turbo, which we're calling Turbo Boost. Turbo Boost is designed as a set of tools that allows for more ambitious and creative use cases with Hotwire.
00:27:11.360 While it’s still in early development, we want to ensure that it organically fits into the Hotwire ecosystem.
00:27:40.560 While we’re currently working on this, we’re also focused on ensuring that the existing libraries receive updates and bug fixes to support users who adopt them.
00:28:21.839 We are also working on building robust tooling for developer experience, including features aimed at enhancing user interaction with Span and other library integrations.
00:29:00.659 Specifically, I'm creating a Stimulus Language Server Protocol (LSP) and would like to offer our first version for VS Code users, with plans to expand to additional editors in the future.
00:29:50.799 As we improve the community-driven Hotwire ecosystem, providing solid documentation is essential. We are working on a website aimed at centralizing features, updates, and usability of Hotwire.
00:30:05.320 Finally, I would like to thank the incredible community and contributors that have been essential in pioneering Hotwire, Turbo, Stimulus, and other projects.
00:30:14.120 I want to express my gratitude to Sam and Javaan for impacting my career and the careers of many others in this community.
00:30:24.120 If you like stickers, I have some Hotwire stickers here; feel free to grab one after the talk.
00:30:35.899 Lastly, I truly believe we can do much more for Hotwire within the Ruby on Rails ecosystem, and that we can maximize its potential.
00:30:46.560 Thank you very much for your time.
Explore all talks recorded at Rails World 2023
+25