React (and Vue, et al) was built with client side rendering in mind. It just does not seem to fit the server side rendering pattern.

What are the use cases? From my perspective, if your app is a rich web app with a lot of interactivity, you probably want CSR and don’t benefit much from SSR.

If you have a content-centric site, or a site with some interactivity but not much, you want a static site generator, or SSR. But in that case, a template engine with some smaller client side libraries (jQuery or AlpineJS or idk what all is out there).

Using React SSR for all of these seems like the wrong tool. What am I missing?

47 points
*
Deleted by creator
permalink
report
reply
36 points
*

The mere existence of the term “server-side rendering” illustrates this well. I remember the first time I read about that concept and immediately thought “you mean the way we’ve been writing websites since the 90s?”

Maybe I’m just out of date, but IMO web development has completely lost its way. I don’t do much frontend work anymore, but when I do my goals are always to see how few JS libraries I need to use and how little JS I need to write in general. The end result of that plus doing all/most work on the backend, sticking to standard HTTP conventions, and using only vanilla JS means super fast and performant websites with fewer bugs, less constant deprecations to keep up with, less security vulnerabilities in all the JS libraries, and no constant headaches from a complex Webpack-style build system for assets. It’s actually quite enjoyable when you remove all the bs of modern JS frameworks from your workflows.

permalink
report
parent
reply
6 points

I remember the first time I read about that concept and immediately thought “you mean the way we’ve been writing websites since the 90s?”

This is a poorly informed take. Your pop’s dynamic html server side rendering has nothing to do with the problem of rendering DOMs generated by JavaScript running in a browser according to the client’s state and leave it in a coherent state. Trying to pass off React’s SSR for the same thing that was done in the 90s is like trying to pass off an Android app as the programs written for DOS.

permalink
report
parent
reply
2 points
*

Is it not generating HTML on the server to be served to the client? What you’re describing is, in my opinion, an overly complicated form of dynamically rendering HTML on the backend. It’s exactly what I’m talking about: the layers and layers of complexity modern web development has added hasn’t really solved any problems but rather primarily created problems which are solved with another layer on top as a fix which has problems of its own, and repeat.

Anyway, that’s my opinion on the matter, I’ve toiled with modern web development tools my fair share and time and time again found that removing all of them in favor of vanilla JS where strictly needed and traditional dynamic backends is the most reliable and performant, and frankly enjoyable form of web development. I know others like those workflows and the complexity/power they bring and that’s fine, it’s not my cup of tea though.

permalink
report
parent
reply
6 points

My hot take is that I find it so much more pleasant to write typescript and do most of the work in the front-end rather than deal with optimizing the response time of the backend day in and day out. With SPAs it’s so much easier to fetch just what is needed rather than have monolithic responses that take ages to arrive. Makes caching and cache invalidation that much easier too.

permalink
report
parent
reply
1 point

Htmx is a godsend for that. You actually write HTML while having AJAX easily.

permalink
report
parent
reply
28 points

Here’s my hot take as a dev who’s been making websites since before JavaScript and css were invented: modern web development is leaps and bounds better than how it was and the rapidly changing best practices had a big part for how we got there in the time we did. I think the industry is in a great place now and now that it is things have slowed down and the focus is now on stability rather than changing development patterns.

permalink
report
parent
reply
9 points

Hello fellow old person. I mostly agree, and I think we’re starting to see some convergence on the core patterns that will define the “best way” to deliver web apps for years to come. The various offshoots of React are really just evolutions to see what fat we can trim and tighten it up. But functional-reactive UIs as a general thing are here to stay and better than all the other ways we’ve wired up GUIs to date.

permalink
report
parent
reply
8 points
*

After experiencing ad hoc inline scripts, frameworkless jQuery spaghetti code, inflexible monoliths like angular, and overly simplistic micro frameworks like backbone, I’m super happy with where we’re at with react and react like frameworks. I really do feel like we’ve hit the sweet spot between power, simplicity, flexibility, and ease of use which is why I’m confident that things aren’t going to be as volatile as the past. React is already 10 years old now and still going strong with no new trends looking to usurp it. I think those old trends were necessary experiments to get to where we are now, and I think the old meme of web dev changing every week is no longer true.

permalink
report
parent
reply
7 points

I agree that things improved. React and others are amazing for CSR. We have static site generators which are also amazing and nice to work with. But SSR territory is in strange place right now. React is overused in places it doesn’t belong.

permalink
report
parent
reply
7 points

I’ve had a good time with react SSR and SSG particularly when using next.js which does a great job optimizing out of the box, but really SSR and SSG are functionally just glorified string interpolators so anything will do. What matters is ease of use and with the strong community and toolset available to react I’ve had no trouble setting up react for SSR/SSG.

Where things still need improvement is with hybrid apps that take SSR/SSG pages and hydrate them to be ready for the client to take over, but that’s always been a pain point, and while we’re still not where we need to be I do think it’s better than it’s ever been and we’re on the right track to cracking it.

Maybe it’s because I’ve seen how bad things can get that I’m appreciative of what we have. After experiencing frameworkless jQuery spaghetti code, overly complicated monoliths like angular, and overly simplified micro frameworks like backbone, I’m really happy with the frameworks and toolsets we have now, and react’s ecosystem is very mature.

I would say that react is overkill for SSR, but pure SSR is pretty simple so react is also able to handle it just fine and elegantly as react is even easier to use when you’re not dealing with dynamic state, and if you find the need to introduce some hybrid client side functionally, which pretty much always happens eventually, it’s a good thing to be on react.

permalink
report
parent
reply
1 point

You can configure nextjs to compile as only client-side-rendering, so that it runs like before!

Another thing: NextJS is not only SSR. It’s hybrid. The advantage here is that it decreases the visible first load time.

First load pre-rendered HTML and styling is sent to the browser. So the page is already fully visible. After that all scripts and secondary CSS will be loaded. And even after that the bindings will be done.

Where as with pure CSR, all JavaScripts need to be loaded and executed and only then stuff will become visible to the user

permalink
report
parent
reply
32 points

I think you may be missing the concept of ‘hydration’. A server side rendered app will deliver the pre rendered markup so that the client has something to immediately display while the framework continues to bootstrap in the background. It makes for much quicker and more efficient first loads, or ‘time to first paint’. A SSR website will still be a CSR website after hydration completes.

In addition, many web crawlers are unable to execute JavaScript. So for many single page applications, or CSR as you call them, they appear as a blank screen to less sophisticated crawlers because the content is never loaded. This is an catastrophe for things like SEO. SSR fixes this issue by delivering the content without regard to JS execution for the initial load.

permalink
report
reply
-1 points

If SEO matters beyond a couple landing pages, I find it unlikely that you would be developing a rich web app with that much reactivity. You are more likely content focused, in which case a static site generator or simpler SSR frameworks are easier and fit the use case much better. Even from a performance perspective, why ship the entire react run time if you do not need it?

And on the other hand, if you are developing a rich web app with a lot of interactivity, then do you really need SEO beyond a couple (or one) landing pages? You should develop the web app in React CSR and build the landing pages as static sites to optimize SEO. That is a lot easier to me.

permalink
report
parent
reply
5 points
*

The biggest issue is flexibility. What if you don’t know if a page is going to need SEO or rich client side functionality when you build it, but then it does later? Do you want to rewrite the page from scratch every time that happens? This is especially true when you’re trying to maximize productivity for junior devs on a large team. Are all devs working on the site knowledgeable enough to make the static site vs CSR call correctly when they first start working on every new page? Wouldn’t a “Use framework X and we’ll figure that part out later” approach be easier for everyone?

Also, what about pages that need both SEO and rich client side functionality. You can choose to limit yourself to only one or the other on any given page, OR you could use hydration to have your cake and eat it too. Maybe react or vue isn’t the right abstraction, but if we can come up with a strong enough abstraction, hydration is a really useful general purpose pattern.

permalink
report
parent
reply
1 point

I suppose I just cannot imagine a situation where a rich interactive web app needs SEO that is not solved by having a separate landing page (and such solution not being way better and less effort than alternatives).

React has enough flexibility to be added later on to a project and not take over the entire web page, but only the parts it manages. It can act as a separate island or series of connected islands. So if you start thinking you dont need react but then later decide you want to add it to your non-react site, it should still be easily doable.

permalink
report
parent
reply
2 points

There are many scenarios you’d want seo and a csr. Let’s say you want a media player. Tons of interactivity, and lots of content. A landing page isn’t going to cut it.

But that’s the beauty of a framework like nuxt or next - you don’t have to choose. You can have your cake and eat it too so to speak.

permalink
report
parent
reply
29 points

I think it’s more a case of the tool being used, not because it’s the best tool for the job, but because it’s the tool the dev knows how to use. SSR allows frontend devs to become full-stack devs.

permalink
report
reply
16 points

That’s exactly how we got Javascript on the backend in the first place. I remember when this was the new “weird” thing.

permalink
report
parent
reply
14 points

React and Vue already have lots of libraries, components, and know-how. You can also move from CSR to SSR and back depending on your requirements.

permalink
report
reply
3 points

That’s definitely the best argument for it, I don’t deny. But I’m glad to see the web components space to be improving as well.

permalink
report
parent
reply
5 points
*

If you have a content-centric site, or a site with some interactivity but not much, you want a static site generator, or SSR. But in that case, a template engine with some smaller client side libraries (jQuery or AlpineJS or idk what all is out there).

React works well in this role too because it supports SSR. This part seems to assume that React SSR is inferior to other classic backend HTML SSR solutions, which is not my experience. Even for static non-interactive content, the way React has you organize your code into components is a much better setup than most classic HTML template systems I’ve used. And then React makes it very easy to sprinkle in interactivity where you want, without requiring you to bridge unrelated server-side html templates and front-end code (which can often blow up in complexity and require work to be re-done separately on each side of the codebase). The same React components can be used in server-side rendering and client-side code, so whenever some new page interactivity requires the client to render something that was previously only server-side rendered, you don’t need to rewrite the component’s code in a new system and maintain two versions of it.

permalink
report
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 3.5K

    Monthly active users

  • 1.7K

    Posts

  • 28K

    Comments