Rails World 2026: Herb in Rails 8.2: Your ERB views, now HTML-aware (Marco Roth) Video: https://www.youtube.com/watch?v=REtfdqtW3PY Talk page: https://www.rubyevents.org/talks/herb-in-rails-8-2-your-erb-views-now-html-aware Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- Thank you. Good afternoon. Hi, my name is Marco. I'm here today to talk to you about Herb in Rails 8.2, and I'm really happy to see that this kind of came to be, and I want to show you what this will enable us to do in the future. If you haven't met, I'm Marco. I'm a developer and open source contributor, and over the past few years, I've been working on hotwire, and I wanted to see how far I can push things with this approach using the HTML of the wire and the web applications. For the last few years, I've been on a mission to improve the development tooling and experience in the hotwire ecosystem, and more recently in the Rails view layer. How Herb came to be. And today, I want to show you what Herb will enable in Rails 8.2 and what it will enable Rails 8.2 to do. So, welcome to Herb in Rails 8.2, your ERB views now HTML aware. I want to talk about what is Herb, what ships in 8.2, and what does this enable. First, what is Herb? Herb is a modern template language for your HTML. Herb is a modern template language for your HTML ERB you already have, and it's one language and one tool chain that understands your HTML and Ruby together. Herb has full semantic and structural understanding of your views, which allows us to build a linter, a formatter, a language server, an engine, dev tools, and also dev server. The engine is what's shipping in Rails 8.2 to render and compile your ERB views. So, in the last year at Rails 8.2, we introduced, we introduced these herb debug tools that you can enable in your browser, and they allow you to show the outlines of the views, give you the link between your editor and the browser, and just give you this interaction and introspection into the views and how they work. This is already really powerful and kind of already showed that this is kind of useful, but we can take this even further. So, this is kind of useful, but we can take this out. So, let's talk about what we do. So, let's talk about what it now ships in 8.2. Action view is what enables this. Action view is what enables this, and funny enough, this kind of logo from Action view from a few years ago, I guess, was kind of hinting at Herb already, with the logo. So, in Action view, we have templates, right, and these are made up of the action itself, the format, and also the handler. 8.2, if the default format for the HTML format, the default is going to be herb, so any format that has the HTML format and any template that has the eRuby handler is going to be served and compiled by herb. And for anything else, we're going to use from 4pack to eRuby, which is the engine that has been used before. There's also a new check and rate task in the 8.2 that you can run in your map to figure out if it's compatible, and whenever this passes, you're safe to kind of opt into the new compilation. There's also a new format or a new configuration to enable this. When you kind of load the default in 8.2, it will set this to herb by default, and if you want to opt out or use the previous behavior, you can set this back to eRuby yourself. Alongside it, we're shipping the new version of herb 0.11, which is the biggest thing we are, and it ships a lot of features we can talk about today, but I want to highlight a few of those, including the LSP features, which now helps you to find references for your partials to see where they are being used, so if you or your agents are factoring your views, they can be more accurate and more instant. We have workspaces support if you have multiple app, a monorepo previews, we have code actions like extracting two partials, and these more new powerful cross-file diagnostics. A new thing we are shipping we are shipping as well is run-time instrumentation, which takes all of your views, which takes all of your views, and looks at every ERB tag, and instruments them, and we can pair them with the existing active support notifications, and we can annotate these tags with the existing notifications. So in this case, we can subscribe to the active record ones for the queries, and then match them back to the ERB tags. We can then return to the run-time diagnostics, which we can show in the browser, which we can show in the browser, including the Lint warnings, and everything else you can see. So you can see the diagnostics, the stack trace, how it was rendered, and if you hover over any of the stack traces, it shows you where the pages actually showed up. This also reworks the error screen, so whenever you have an error, or it's hot reloading, and shows you an error, you can see this like this, so you know what's going wrong. And we can see this, and we can see this, and we can see this, and we can see this. And we can see this, and we can see this, and we can see this, and we can see this. And we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this, and we can see this. And we can see this, and we can see this, and we can see it, and we can see this, and we can see it, and we can see it, and we can see it, and we can see it in the demo. And we can see it, and we can see it, and we can see it. And we can see it, and we can see it, and we can see it. And we can see it in the browser as well. that we also looked at all the translations. So whenever you have them, you can overlay them over the existing code. And when you put your cursor on the actual line, you can see the source behind it. There's also a total of over 16 lint rules, which helps. And you and your agents write more and save view codes, which now makes up over 160 lint rules to make your views more sane and sound. All the new contributors for this release. This is the biggest and most we have seen so far. And all the 30 ones that have been contributing to this release specifically. If you want to read more about this, there's going to be a blog post on the Herb blog about all the new features that are shipping in Herb series 11. So now, what does this enable? Because the Herb foundation is now in all apps and all new apps and all the existing apps that are operating, we have the compiler as a platform, which means you can build more more things on top of it. And Rails famously has been the one-person framework, which with Rails 7, we got the whole simplification of hotwire and this whole HTML over the wire approach. And with Rails 8, we got the simplification of the solid trifecta and the whole SQLite. But the one thing I felt was that the view layer itself doesn't scale the same way as the rest of the framework. So I was asking myself what becomes possible when the whole engine, the runtime, and everything else understands it understands the HTML in your views too. And how can we evolve hotwire into this competitive and how can we evolve hotwire to build more competitive and more modern and ambitious UIs. And then finally, what it takes to complete this hotwire story now. And in my opinion, what we are missing is this idea of reactivity, or more specifically, the fine-grained reactivity. The design goal for Herb itself was that you can take any of the existing ERB views, and they should be backwards compatible with all the tooling. And they should be backwards compatible with all the tooling. And I was asking myself if we can do the same thing for the templating, the reactivity, and the interactivity, so you can write more interactive UIs. And I wanted to explore if there is any of these ideas we have from stimulus reflex over six years ago, and if we can bring them back into this idea or in this mix. So I was looking at all the existing frameworks that we had, including stimulus reflex, and Turbo, Phoenix live view, which does very similar things, live via PHP, inertia, and the whole kind of set of SPAs from JavaScript. And that's the idea of reaction view. We wanted to take a look how we can take action view and try to reimagine some of these things, how we may be able to re-engineer some of the things if you need to, and finally to make it actually reactive. To show that we have been working on this reaction release to ship this new big release, including reactivity. And I want you to take a brief look at this clip here. Thank you. Thank you. So, I'm happy to release reaction view 06 today, which makes all your existing views reactive by default. So, it's reactivity for the HTML ERP you already have. With the idea that everything a client-set framework does, you can now get without having to adopt one. And the best thing is, you actually already wrote a reaction view template already. Because as I said, all of your existing views are now reactive, and that just works out of the box. By default, they are in the servo mode, so you just have this basic reactivity, but you have the option to go further and add more interactivity to it, so it's kind of gradual how you want to adopt it. So, it's kind of gradual. and all the way that you want to do that. the first time you have the first time. So, the second one. So, the second one, the second one. So, the second one is for any subsequent requests where you have the next one. So, the second one is for any subsequent requests where you just send back or send down the new values dynamic. So, if you take a look at this here, we have this very simple template with a title. If you pass the title and render this, you get this in the browser and this is what the browser sees. But the browser cannot tell anymore that this part of the template came from this one specific ERP tag. This is like detached. So, what we can do is we can insert HTML comments to split up this expression. So, the disk part here is we can do this part here is we can do this part here is we can do this part here is we can do this part here is still addressable and that we can specifically update them without having to do a full page reload and a full morphing operation. So, we can do this part here is still addressable and that we can specifically update them without having to do a full page reload and a full morphing operation. So, we can give us a way to address any ERP tag and just update them specifically. And if you wrap this in a tag for the region, we also know where this came from, for which partial, which file, which file, which file, so we can address this specifically. And if there's a new value, we can just update that and that's how it works. So, both the server and the client have a map of where the dynamic values go and they also know how to update them. And it doesn't matter where the new servers are coming from, so you can send them over HTTP, over action cable, over service and events, or even from client side itself, it can update and reflect these changes if it's having to re-render them on the server side. So, we have this idea. We have this idea of outputs, the slots, the collections and conditionals, and that's kind of all we need to make this all work. And as I mentioned, there's no full page reloads, there's no dumb morphing, it's just these efficient updates that know exactly where these values go. So, let's take a look here. We have a simple template, just time.now, and we have the output at the bottom. So, what we can do now is we can add a new button here and we can say, I want to say, I want to have a refresh. And you can see, at the bottom, it just did the whole live reload in the browser. So, if you have a new data herb action, which is similar to stimulus data action, and you can just tell it to, whenever you click this, you want to refresh the page. And this is all you do. This is all you have to wire up. So, if you click the button, it will refresh the page and it will show you the new dev tools, which of the slots updated and how they reflect the changes. So, that's kind of all you need to wire up. Behind the scenes. Behind the scenes, it does a get request to the same URL you are currently on. And it sends this accept header with it. And our action in the controller is just pretty much empty because there's nothing that we are doing there, right? Rails implicitly responds to this using the format for HTML. And ReactionView adds the second format implicitly for the slots. So, the first request is still HTML and any subsequent request with this header set is going to compile. And this is going to compile and render through the slots format. And the slots format itself is pretty much just a representation from a schema of this exact template. So, we can see this template has five slots. So, this is going to return five slots too. And because the client knows about the schema or how this works, it can then take these values from down here, from slots number one or zero, and then up this in the client side. And that's kind of cool. That's kind of how this works for just the basic functionality. But if you want to go and make it. But if you want to have the basic functionality, but if you want to go a step further and make it even more dynamic, we want to have UI state too. So, UI state just means that you have some kind of variable that doesn't go to the database, doesn't have to be persistent, but you just need them to show and hide things or update things in the UI. Because I believe that not every UI interaction itself needs to go and do a server round trip. And typically, you would kind of use stimulus for this, to just write a stimulus control and wire this all up. But what if you can just write a strategy instead? So, if I would write a template here, I would have this show. So, if I would write this template here, I would have this show predicate method with this if condition and say whenever this is true, I want to render this output. So, we have this new directive now for herp state which works the same way as a strict local. In this case, we are defining a show state with the default value of false. And because the compiler knows now this is a state, it has this show down there it just knows what to do. So, it knows what to do. So, we can say when we click this button. So, we can say when we click this button using the state of herp set, we want to set the state of show to true. And this works the same way as stimulus. So, we can also leave out this click because it's a button. So, it implicitly thinks it's a click. And with that, we pretty much got this all wired up to say whenever we click this button now, it will show this conditional. And this is all in the client without having to do a server request. So, this is all in the client. So, this is all in the client. And this is all in the client. So, we know how to parse and process this because we have all the tools. So, I was thinking if we have this input, we know it's a value. And if the sole value of this attribute is just an ERB expression, why can we just not bind it in the compile step? So, if you define message as a herp state, in this case, as an empty string, this message state is now bound to the value of this input. That's how we get a two-way binding. So, if we get a three-way binding. So, if you want to update your view and add more dependent data on it, you can type into the fields and it will update accordingly now, knowing that the message length depends on the state value. And whenever you type into the field, it updates the state and reflects all the changes. So, you just write declarative markup and it knows how to reflect the changes. As I mentioned, there's no native request here. There's no custom JavaScript. It's just a pure understanding of this template and then these efficient updates. We also don't need any Ruby to try our scope transpilation for this. And we also don't need Ruby and WebAssembly in the browser to execute the Ruby. Because reaction view sees all the methods and all the herb states and can analyze them. And the compiler knows about a subset of Ruby from the typical kind of operations you do in views and can bake this right into the reactivity model and wire it up right there in the compile step. So, that way, we can run all of this in the client without a server round trip. And for everything the compiler doesn't understand, because it's too complex or because it requires a SQL query or some database or something else from the server side, we can do a network request as a fallback. So, let's take this example here. We have a state for queue. It's a search. And then down there you see topic search and we have queue in there. So, the compiler sees we have this queue state. It knows this ERB type of the topic search is dependent on this queue state. So, whenever queue changes, it can update and reflect the changes and go fetch from the server side, get the slot format back, and then reflect the changes in the front end. And if you look at this, that's just how you write ERB. I have been writing ERB the whole time, but it's just reactive now, which is super cool. So, the pilot knows about the client. So, the pilot knows about the client. So, the pilot knows about the client. So, the pilot knows about all of this. It prepares the view for the client and it has the counterpart on the server side. So, whenever the state changes, it knows if it can do it all client side or if it has to reach back for the server to get the new values. And if the client actually has to fetch from the server, the server knows exactly what could be coming from the client because it already saw all the templates. And then the client knows how to reflect these changes because it also knows how to look at the schema. There's no idea how to reflect these changes. There's no idea how to reflect these changes. So, there's no idea how to reflect these changes. There's no idea how to reflect these changes. So, let's say we have this kind of template with a slow query in here. But instead of having to write and extract this into a separate partial, having to expose it on a separate route, what if we just wrap this in an async tag? This is an async tag with a capital A. It's not, I guess, typical from what you see, but from other frameworks, especially in the React world, you have a lot of these built-in components. So, this kind of takes it and makes it async. So, this is an async, which means, which means we want to provide a fallback for the first time, which means we want to provide a fallback for the first time. So, the compiler sees this setup. So, the compiler sees this setup, knows there's a skeleton here, and whenever you render it for the first time, it just renders the fallback, which is super quick. And then, whenever this comes to the client, the browser sees this, it knows that this is an async block and can talk back to the server, fetch the values, and then bring in that actual new data. So, it works with a lazy, which is a lazy, which is the same thing, which is the same thing, but only when it comes into or near the viewport, it starts fetching. So, here's a short demo for this. You have the page, you see the value loading, and when you scroll all the way down, it starts fetching and then brings in the value, just using this declarative state. I'm open to feedback about naming this, because this is just the way I came up with a lazy, which is the same thing, but only when it comes into or near the viewport, it starts fetching. So, here's a short demo for this. You have the page, you see the value loading, and when you scroll all the way down, it starts fetching and then brings in the value, just using this declarative state. I'm open to feedback about naming this, because this is just the way I came up with this. So, this is just the way I came up with, but if you have any more idea about syntax and naming on this, I'm open to feedback here. And then I wanted to kind of show what's possible with this, with just ERB. So, I built this kind of music player or music library. Whenever you click on it, it kind of shows immediately the details about it. It shows the skeletons for loading. You can play back some of these tracks, pause and play, and then close it again. And this is like 100 lines of ERB, no JavaScript, and that's kind of what you're able to build with this now. And then finally, this whole idea about optimistic UI, because we have all this understanding now, we can push it all down to the client, park our markup there, so we can do client-side rendering. So, here I have a simple app, a chat app, which I can send messages into, and these messages get rendered on the client-side immediately. And whenever they might fail, they also can render instantly on the client-side, so you can retry them, and then send them to the server. You can edit them. This whole interaction is also just client-side. You click the button, you click delete. This doesn't need a round-trip, because it's all just hiding and showing things. And then finally, the star from the message, the star is happening immediately on the client. It queues a request in a queue. And whenever that request. And whenever that request might fail, it can roll back to the last state it knows was good, because it takes a log of all the state changes that happened. So, you can kind of go back and forward in state changes. So, that's kind of to show that I think you can do a lot of pure ERB now, just having this pre-compile step and this compiler, knowing about your view, you can build this interactive UIs. And if you need more, if you want to build this more, even more ambitious, even more ambitious UIs, there's a JavaScript API that you can use to interrupt the runtime directly, which you might be wanting to use if you want to use any NPM packages or any more, like, click events or whatever. There's just a low-level JavaScript API you can use for that, too. All you have to do is add the ReactionView gem, run the generator, and that's what you have to do. That's it. There's docs on ReactionView.dev, and the demos I've shown today are on ReactionView. Take a look at the code. It's all open source, so you can see it for yourself. So, I want to give a quick outlook of where everything this could be heading. The one thing we have been doing and seeing from people is that there's still a struggle of managing CSS and JavaScript, so we have now also this style scoped idea, so you can put a style tag into your ERB view, and they can scope it just to one specific partial, so the styles don't leak. We have a new gem. We have a new gem for this called Lightning CSS Ruby, which does all the preprocessing. It's a tool written in Rust, and it has Ruby bindings now. We just kind of call out to this, do some of the modification, and then it's scoped to just this one specific page. We haven't been working on script scope yet, but I think there's also a potential where you want to put a script scope into your view, where you have all the scripts just applied to that one specific page. For that, we have built of OXC Ruby, which is the tool in Rust that the Bundler uses, and the Bundler uses, and it's also something we use under the hood to bundle JavaScript, which means you can use TypeScript, you can use JSX if you really want to. This can bundle it without having any JavaScript installed, so you don't need Node.js, and it's still all compatible with input maps. And if you have to take a look now, I think there's also more opportunities now to do an actual proper and offline mode, because we can push all the markup down. There might be a possibility to add components to the mix now, to go side by side with the ERB. And more importantly, I think there has been missing an abstraction for components that gems could provide. So, if a gem can provide a component that has a server and a client-side part, then you can just bring them into your view layer, and the herb engine knows how to deal with them. So, to conclude, I think I'm not. I think I'm really happy with it. I think I'm happy with where this direction of Herb is going, and how these things are shaping up, and that we can now pretty much go back to just ERB views and Ruby to have these full reactive UIs. And if you take a look at the bigger vision, I think that this could provide a great foundation for the future of the Rails front-end, and that this kind of tries to offer a spectrum of solutions for teams for how much they want to adapt to their stack. And most importantly, and most importantly, and most importantly, and most importantly, to expand what's possible with Hotwire, so we can keep the simple approach that Rails always kind of try to prove and make it even more powerful. And if the application really needs it, that you have a way now to write more JavaScript if you really want to. That's what I mentioned. I just want to also provide a way that if you have existing React components, I want to use them, that you have no way to do this without having to abandon this full-struck idea, which makes Rails so special. So, that's why I'm really happy that Herb made its way into Rails, because this provides the foundation now for all apps to build even more powerful things on top of it. ReactionView has become what I always wanted Stimus Refix to be in a way, but I'm sure that we are just at the start and we can build even more things if you start on this. But I can't do it all by myself. But I can't do it all by myself. I need inputs. I need more real applications, more real adopters that try to push what's possible with this. And I would love to talk to you if you have any ideas, opinions on all the things I've shown today. Or if you're skeptical and have questions about where this is heading. So I would really love your input and feedback. And finally, I want to give some quick feedback. I want to give you a shout-outs. I want to give you a shout-outs. I want to give a shout out to you. I want to thank you for the support. I want to give you a shout-out to the people that have been able to share the information. And I want to give you a shout-out to the people that have been able to share the support. I want to give you a shout-out to the people that have been able to share the information. I want to give you a shout-out to the people that have been able to share the information and help you to share the information. And finally, to all the sponsors that have been supporting me on this journey. Thank you for the community support. Please try the tools, report issues, and give feedback. Give it a star. Thank you for the top for both Herb and ReactionView. Check out the new docs with the new landing pages on ReactionView. And that's what I have for today.