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?

  • Kev@beehaw.org
    link
    fedilink
    arrow-up
    26
    ·
    10 months ago

    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.

    • Cyclohexane@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      arrow-down
      4
      ·
      10 months ago

      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.

      • zevdg@lemmy.one
        link
        fedilink
        arrow-up
        5
        ·
        edit-2
        10 months ago

        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.

        • Cyclohexane@lemmy.mlOP
          link
          fedilink
          arrow-up
          1
          ·
          10 months ago

          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.

      • Kev@beehaw.org
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        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.

  • charliespider@lemmy.world
    link
    fedilink
    arrow-up
    22
    arrow-down
    1
    ·
    10 months ago

    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.

    • lightsecond@programming.dev
      link
      fedilink
      arrow-up
      14
      ·
      10 months ago

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

  • lightsecond@programming.dev
    link
    fedilink
    arrow-up
    10
    ·
    10 months ago

    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.

    • Cyclohexane@lemmy.mlOP
      link
      fedilink
      arrow-up
      3
      ·
      10 months ago

      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.

  • Macil@programming.dev
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    10 months ago

    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.

  • ShortFuse@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    10 months ago

    SSR is a overloaded term.

    • There’s SSR to help improve FCP (first contentful paint). This is not really so much an improvement to the client side framework as it is a crutch to workaround the fact that the frameworks are dynamically constructed clientside. But the first paint would just be Root node which is essentially empty. Because React and Vue are so heavily tied to the DOM structure, it expects to be the compositor of the tree, not something written in HTML. For pure HTML to be the compositor, you would need to add some rehydration to React/Vue to take a pre-composed state and reintegrate it into what React expects.

    • SSR is also used to dynamically build content that is presented to the user that is not necessarily tied to rendering. This is popular with PHP, where instead of putting a blank table and then having the client fetch content over JS and then populate that table, the server just hands you the precompiled HTML. Not all the data as sent over JS may be useful (eg: only 10% is used after filtering and pagination), so to save transfer size and query latency, it may be the server that gets the always data from the store or cache. There’s less client JS in execution, which may also help in performance.

    • Then there’s SSR for the purpose of improving SEO. This relates more to the first point, but maybe the first paint isn’t important. Maybe client-side construction is plenty fast. But because the root is just blank, search engines that don’t perform synchronous JavaScript can’t actually read the content being shown to the user after all the rendering is said and done.

    Personally, I’ve moved to Web Components that solves almost all of this. You can author layouts in HTML and anything that you want in your HTML file for SEO is included in the source. I would only use SSR to target the second issue, where you want to save on trips to build dynamic content. It is somewhat wasteful to give clients instructions to fetch and render when the server can do that on the first trip. The issue is rehydrating, or picking up from that state, but that truly depends on how complex your Web Components are. If they are sparse and simple enough, then all states should be able to be expressed over attributes. First paint can be reduced with the template shadow root, but I feel it’s more trouble then it’s worth and has negligible performance gains compared to just doing a prerender JS to register components and the browser will only render synchronously what’s in the viewport anyway. That means time to first paint is not dependent of how big your page is. It’s only dependent on how many elements you want to register before DOMContentLoaded.

    From a financial aspect, I’m not about to ditch static CDNs to reinterpret nearly every single request with some server for SSR. The costs are nowhere near the same to try to reinterpret with SSR. You can micro-optimize to death with a SSR to CDN route and then hydrate, but I feel you risk complicating deployments to where you’re so vendor-locked you have extra hoops to jump to make changes. God forbid you want to change frontend systems. At that point the DX pain is too much to justify and wanting to get out is inevitable.

  • T (they/she)@beehaw.org
    link
    fedilink
    arrow-up
    2
    ·
    10 months ago

    By my understanding on the matter, it depends on use case. Ecommerce websites benefit greatly from SSR due to the fact that they want to be able to show content as quickly as possible so the user have something to interact with. It also improves SEO.

    • monad@programming.dev
      link
      fedilink
      arrow-up
      6
      ·
      10 months ago

      Well that’s why you would render on the server, not why you would use React to do it instead of the many, many server side frameworks

      • jcg@halubilo.social
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        But then you’d be sacrificing all that comes with React. Unless you mean having the page rendered by another framework and having React components loaded later, but I’d think that would be less maintainable than if the whole thing was just in React.

  • EvokerKing@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    Technically base html, css, and js are client side, so it is easiest to continue that. If you want something node based that is server, use express with stuff like mustache.

  • exapsy@programming.dev
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    10 months ago

    Cozx we went to a full circle. Back to sveltekit now until we find a better solution. Back then Virtual DOM was a feature, now it’s more of a bug.