loco-rs / loco

šŸš‚ šŸ¦€ The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
3.63k stars 153 forks source link

Develop an approach for frontend/UI #130

Open jondot opened 7 months ago

jondot commented 7 months ago

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:

  1. If Loco provides UI, will it be Rust or js based? Is it possible that we won't provide a UI at all?
  2. How can you make use of the auth feature more easily (provide forms and UI), like Rails' devise
  3. What kind of starting (starter template) will we offer to make people more productive in this regard?
  4. If possible gather feedback from other people of what they would expect (keep the audience wide, e.g. no bias for Rust-based frontend)
gbj commented 7 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...

jondot commented 7 months ago

Thanks @gbj this is what I'm taking from your thinking:

jryio commented 7 months ago

Here are a few thoughts in addition to @gbj's great comment

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.

suleymanozkeskin commented 7 months ago

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.

AvidDabbler commented 7 months ago

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.

jondot commented 7 months ago

I'm distilling some more of the feedback:

1cg commented 7 months ago

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.

1cg commented 7 months ago

also suggest supporting both a hypermedia API & a JSON API on different end points easily:

https://htmx.org/essays/splitting-your-apis/

https://htmx.org/essays/hypermedia-apis-vs-data-apis/

jondot commented 7 months ago

Are there any big "in the wild" uses of htmx?

1cg commented 7 months ago

hgtv/food network is starting to use it: https://www.foodnetwork.com/holidays-and-parties/photos/top-holiday-cookies

some others:

https://www.nikevision.com/

https://light.berkeley.edu/nobels/

mistral is using it: https://jobs.lever.co/mistral/586bc657-f593-4a1e-90c6-06ca3838d5a5

there's a webring here:

https://htmx.org/webring

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.

jondot commented 6 months ago

Thanks!

Some more community updates from Loco:

Edit:

1cg commented 6 months ago

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):

https://hypermedia.systems

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:

https://htmx.org/discord

kaplanelad commented 6 months ago

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.

narup commented 6 months ago

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

HatsuMora commented 6 months ago

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)

brohithkr commented 5 months ago

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.

jurukode commented 5 months ago

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:

stefan-vatov commented 5 months ago

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".

kaplanelad commented 5 months ago

hey @stefan-vatov, we are going to release server side rendering next week

thebl1985 commented 5 months ago

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.

rubiktubik commented 5 months ago

+1 for templating support to be able to use htmx

jondot commented 5 months ago

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

rubiktubik commented 5 months ago

Very exciting! With your framework, rust has reached a new level of versatility. Keep up the good work

kaplanelad commented 5 months ago

The version was released 0.3.1

jondot commented 5 months ago

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.

em-jones commented 3 months ago

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:

astro's pages

remix routes

blazor's route templates

tanstack router - typesafe routing

Things that I see lacking in some/all places:

It looks like Loco is very much headed in the right direction. Don't stop!

laojianzi commented 1 month ago

htmx is a good choice, and if it can be like templ, there can be