Open jondot opened 11 months ago
(Came here from your Reddit post.)
"Productivity" is probably the most subjective possible metric here. The range of answers you've already either proposed gotten on Reddit is so wide as to cover the full spectrum of things that could possibly run in a web browser, from slint (doesn't even use HTML/DOM but renders into a canvas) to Hotwire (doesn't do any frontend but diffs new HTML from the server). Maybe this reflects the fact that people are the most productive in the tool with which they're most familiar.
That said, a few technical points:
Given all that, personally, I'd very strongly recommend you choose a Rust HTML templating approach that you like, and make it obvious to people how to return HTML in a blessed way. (I don't see this at the moment in examples or docs but will admit I haven't read them thoroughly.) You could build "and here's how to have a React frontend that only supports half of React's features and adds a bunch of additional complexity and build tooling" but if someone wants a full-featured framework using React they're just going to go for NextJS anyway...
Thanks @gbj this is what I'm taking from your thinking:
Here are a few thoughts in addition to @gbj's great comment
Loco is and will try to be opinionated, which is the appeal. However choosing a frontend framework / style / approach is effectively taking a dependency out on that technology. Whether it be JavaScript, Rust (Dioxus, Leptops, Yew, etc.), or templating.
A follow up question is: how often will that dependency 'churn'? How many major versions will Loco have to keep up with? How reliable and performant are the build systems surrounding those tools? E.g. Most JS build tools outside bun.sh and maybe esbuild are going to be slow. Plus the JavaScript ecosystem can quickly lead to heavy weight applications.
Assuming anyone can use Loco to build JSON APIs and then build their own separate Single Page Application at any time, it would make the most sense to me to have Loco be opinionated about HTML templating and have guides, examples, support for building and serving SPA bundles which are framework agnostic. Effectively an escape hatch. Ruby on Rails, Phoenix, Django, and every other opinionated web framework support this.
Back to basics, if Loco is going to be the single developer company framework for Rust, simple, effective, and performant are likely top of the list. I think HTML templating or something optionally interactive like HTMX are good choices.
It's worth mentioning that I am an admirer of Leptos and think it's excellent, great work @gbj. If I were using Loco myself for a personal / side project I would choose Leptos to continue working in Rust, reduce my language switching, and share code and types. In SaaS or general business environment, templating is safe and predictable.
That's my two cents, I'd love to see the other pieces of feedback from the community focused on tradeoffs and expectations for opinionated web frameworks.
Allowing users to pick either React or a Rust based frontend framework at the same time seems like the most inclusive option. I know that this would increase the complexity which goes against the idea of minimalism, however react ecosystem is mature, well supported in many ways. In my opinion, this approach would probably catch attention of more developers. As @jondot said,
"including a very small subset of Rust developers that are actually willing to do frontend in Rust"
could be a mistake moving forward. At the moment, attracting more developers seems like the better decision.
I started thinking that React was the obvious choice for this, but after reading a lot of the comments about the complexity it would add I think I would like to see htmx as the de facto template and a rust frontend for type sharing if needed. It would be nice to be able to go either way on this depending on page complexity.
If the user really wants to use react I'm sure that you would use loco as an api with your front/full stack of choice.
I'm distilling some more of the feedback:
if you decide to support htmx and have templates, consider supporting template fragments w/ whatever your templating solution is:
https://htmx.org/essays/template-fragments/
this makes it much less annoying to decompose a view into dynamically updated bits by avoiding template file blowout.
also suggest supporting both a hypermedia API & a JSON API on different end points easily:
Are there any big "in the wild" uses of htmx?
hgtv/food network is starting to use it: https://www.foodnetwork.com/holidays-and-parties/photos/top-holiday-cookies
some others:
https://light.berkeley.edu/nobels/
mistral is using it: https://jobs.lever.co/mistral/586bc657-f593-4a1e-90c6-06ca3838d5a5
there's a webring here:
but it's not backed by any of the big tech companies. I know one FAANG that is using it for internal tools, but can't say which.
Thanks!
Some more community updates from Loco:
cargo loco generate deployment
)Edit:
cargo loco generate scaffold
, as in a full scaffold for interacting with entities. For example, if htmx is chosen then we'll also have a basic CRUD UI using it. This resolves the meaning of "supporting frontend" in Loco.some other alternatives if you want a hypermedia-based front end lib out of the box:
we also have a book (free online) if you want some background philosophy on the hypermedia approach (esp. the first two chapters):
and we have a #rust-htmx channel on our discord if you want to talk to rust users who have worked w/ htmx. Obviously severe selection bias, but maybe useful for practical experiences:
We created an example of how to serve/develop a front-end app with Loco. Blog Repository
It will be greate to get your feedback.
I would vote for starting with htmx. I could be wrong but most of the folks who will adopt Loco will be mostly backend developers trying to build a full-stack app or SaaS so making frontend development easier will be really helpful. Rails is pushing for that as well with hotwire and even plain old CSS
Hi, Just started to learn Rust but come with some Ruby on Rails knowledge... My two cents, for quick prototyping / solo framework my go to preference are frameworks that have HTML templating, it is good enough for my hobby or personal projects. Even if it means to reload the full page on each request. Not writing a client application is worth the overhead of full reload.
This is only a problem when building customer facing application because the current UX expectations from the users, and normally a rich UI + API will be the way to go. And this is already supported (API side)
Maybe Look into Slint UI. It's a language (kinda) for creating ui for Slint apps. The UI written in Slint supports adding logic in rust or any other language and it gets compiled natively to system. It's syntax approach is almost like flutter, hence it would also improve productivity. Though people have to learn a new tool, it's pretty easy to learn.
For Leptos, I think it's better to contribute to their end since they have templating mechanism for each web framework (currently actix and axum).
So, Loco can just focus providing the backend and let Leptos handle the frontend matters.
That should be much flexible.
References:
Hi, Just started to learn Rust but come with some Ruby on Rails knowledge... My two cents, for quick prototyping / solo framework my go to preference are frameworks that have HTML templating, it is good enough for my hobby or personal projects. Even if it means to reload the full page on each request. Not writing a client application is worth the overhead of full reload.
This is only a problem when building customer facing application because the current UX expectations from the users, and normally a rich UI + API will be the way to go. And this is already supported (API side)
I agree here, found loco by searching "rails for rust". I was looking specifically for something that would allow me to iterate fast without fussing too much about the UI stack. Almost expected the project to use something like https://github.com/Keats/tera for the templating out of the box.
The whole alure for me is the speed and productivity gains that can be had. Think Rails for Ruby or Phoenix for Elixir.
Server side rendered templates feels like the only missing big piece from "Rust on Rails".
hey @stefan-vatov, we are going to release server side rendering next week
I don't want to just leave a +1 but loco supporting templating/htmx is literally the only reason I will go back to doing frontend development after 10 years of avoiding it like the plague because of the javascript hell it turned into.
Really looking forward to this.
+1 for templating support to be able to use htmx
If you want to see how server side rendering will look like it is in master here: https://github.com/loco-rs/loco/commit/f6fae06fe52dd60eec825e7ec625f6f62ef819f5
Very exciting! With your framework, rust has reached a new level of versatility. Keep up the good work
The version was released 0.3.1
Views are now out! https://loco.rs/docs/the-app/views/
It should cover all bases. Anyone who wants to experiment with HTMX is now welcome. This should enable using HTMX more easily.
This iteration looks fantastic. Great work, everybody.
I want to share some thoughts as a polyglot engineer that's having a difficult time finding satisfaction in any ecosystem.
Places that I see view logic being done elegantly:
htmx
or something of the like, I can directly depend on the services that are going to be useful to me - no controller glue required(I'll save that overhead for my json apis)htmx
and it's siblings offer a similar user experience with "onLoad"-based triggersFormData
directlyThings that I see lacking in some/all places:
lsp
(makes maud
actually feel like a better solution than others in the rust ecosystem)It looks like Loco
is very much headed in the right direction. Don't stop!
htmx is a good choice, and if it can be like templ, there can be
The best approach is one where the front-end is written in something that's somewhat native to the front-end but still allows for static typing. Something like TypeScript and since it's for the web, it's going to have better interop with the ecosystem of libraries for the web. One of the biggest mistakes Phoenix (Elixir) did was to go their own way and its eco system is minuscule and spread thing compared to TypeScript.
I hope this doesn't come across as a shameless plug, however I might have a solution for the remark by @jondot :
- Give people an option to integrate React if they would like to, but do not own that approach. For example add static file serving, and offer some snippets to configure webpack, vite, to use Loco as a server. Also show people how to deploy their Loco server as well as bundled assets.
I've created a small library called in-vite today. Which allows you to integrate Vite bundle's into your Rust backend (both during development and production). It even implements the necessary traits to use it with Tera templates:
<!DOCTYPE html>
<html>
<head>
{{ vite(resources=["./src/app.ts"]) }}
</head>
</html>
The function vite()
then generates the appropriate <script>
- and <link>
-tags required to load your bundle and chunks.
A small bare-bones example with for Axum & Tera using Tailwind, AlpineJS and Typescript via Vite can be found here.
Note, that this is my first public Rust library and thus might be a bit rough around the edges. Your feedback is welcome.
Personally, I would like to stick as close to Ruby on Rails as possible. I really like the direction of Ruby on Rails version 8. Things like Hotwire, frames, etc mean you don't need to have heavy front end framework. I like this. I feel the direction of frontend architectures are going very complex with SSR and Hydration, etc. If you watch the Ruby on Rails 8 keynote, think you can see a much better approach, especially when we consider "one man" projects.
Hey there. I feel like this would be a pretty good place to find people using Tera and potentially htmx together ;)
I'd like to make it easier do complex templates in the next version of Tera as well as making it easier to integrate with htmx/livewire-like things with more targeted re-renders (block/component level). In practice this means adding the concept of components to Tera (similar to React/Vue/Solid etc) to replace macros (which are almost the same thing). The goal being to make a template engine where making complex UI feels as easy as React/JSX.
If that sounds interesting, I would love some feedback on https://github.com/Keats/tera2/issues/51 (and any other Tera feature request tbh, this is the right repo to ask)
@Keats I think this would be awesome!
Currently Loco offers html output as a starting point for UI. We have decided to not decide about frontend, so that we can focus the thinking on it separately, and now have come the time to start thinking about frontend :)
Principles:
Insights
Output of this task Answer the questions: