3 ms·
I'm trying to build server rendered websites, but I find React (or other SPA-API systems) hard to resist: - Form is hard. Doing it in backend make it even hard
by whs 2y ago
I'm trying to build server rendered websites, but I find React (or other SPA-API systems) hard to resist:
- Form is hard. Doing it in backend make it even harder when the form is complicated. For example, a form with tab needs JS to operate and you need to signal the JS which tab the error is.
- If you're using backend form framework, you don't have control over the HTML unless you learn the hook points of it (do you add attribute in code, or in template? Where is the default template to override?) Compared to frontend framework where you can paste the CSS framework's example HTML.
- I wanted to build a new user wizard, which should be easy with a frontend framework as you can easily store incomplete state in memory. If not using JavaScript one would have to store the state in the untyped session variables, add hooks cluttering the HTML template, etc.
- Progressive enhancement is easier when you have to write the code only once. If there's a table and you want to refresh without refreshing the page, in React you just call the data fetcher again. In HTMX your backend needs to have a "full render" endpoint and a "table only" render endpoint. If you're using jQuery you might as well write the table loop twice in the backend template engine and in jQuery.
- I haven't see any good backend framework (be it Django, Laravel, Symfony, Gin) that has similar server-rendered frontend component like React. Many frameworks believed that logic should be precomputed in the view layer and the template engine should not be turing-complete.
I was thinking about moving to SSR-rendered SPA, but I know of no Next.js-style library for any frontend framework that actually allow form submission without JavaScript AND progressive enhancement with JavaScript using the same code.
- pier25 2y ago> a form with tab needs JS to operate Yes, this use case is better solved client-side but even in an SSR app you can always use rich widgets/web components in React, Preact, Vue, Svelte, etc. > I wanted to build a new user wizard Use some JS component(s) or web component(s) as I pointed out earlier. > In HTMX your backend needs to have a "full render" endpoint and a "table only" render endpoint See fragments: https://htmx.org/essays/template-fragments/ https://htmx.org/essays/template-fragments/ > I haven't see any good backend framework that has similar server-rendered frontend component like React Plenty of backend solutions give you SSR components that are composable and where you can colocate template with backend logic. See Razor pages in dotnet or Astro. > but I know of no Next.js-style library for any frontend framework that actually allow form submission without JavaScript AND progressive enhancement with JavaScript using the same code I'm 99% certain SvelteKit and Remix allow you to do this.