Comment by lmm
4 years ago
> If this were true, you wouldn't need a REST API. I don't understand what you're trying to say here. When you make a REST call to get data, you instantly have two different sets of state: the client and the server. It's no different from SSR, it's just transmitted in a different data format (json vs html).
SSR means you don't have a clear representation of the client-side state (as distinct from the presentation) - by definition you render on the server and only serve the view layer to the client, whereas your data model only lives on the server. There will naturally be state in the client (e.g. form inputs), but you don't have a good representation of that in your model.
> You do the exact same thing with SSR. Stateless shared nothing app tier instances. Been doing it for 15 years now.
OK so where does the UI state live - not the long-term persistent entities, but things like unvalidated form input, which tab is enabled, which step of an in-progress wizard the user is on? Either you manage that on the client (at which point you're halfway to an SPA, and getting the worst of both worlds), or you manage it in the application layer on the server (in which case you have all the scaling issues), or you make every UI change go all the way into the data layer which has even bigger performance issues.
That state lives on the context of the page. That's the point of having a URL/page lifecycle that reloads the context.
If you need to persist past a reload then a few lines can save to localstorage. Anything more requires server-side calls anyway.
This magical state that can only be managed on the client-side with a heavy SPA is a myth for 99.9% of sites.
> If you need to persist past a reload then a few lines can save to localstorage.
Sure, and pretty soon you've got a dozen random little copies of bits and pieces of your state, all out of sync with each other.
> Anything more requires server-side calls anyway.
The issue isn't whether you need server-side calls (ultimately every webapp needs server-side calls, otherwise why would it be a webapp at all?), the issue is whether your framework can manage client-side state between those server-side calls. In theory you could create a server-side-rendering framework that was good at this. In practice, none of the big names has succeeded, and certainly not without significant costs. (I'd argue that Wicket does this well to a certain extent, but it comes at the cost of both relatively heavy server-side session state and significantly more network roundtrips than SPA style).
> This magical state that can only be managed on the client-side with a heavy SPA is a myth for 99.9% of sites.
On the contrary, 99.9% of sites have or could benefit from having some amount of client-side state. Any time you have a stateful UI, there's a usability benefit from persisting that. Any time you have so much as a form field - like the text box I'm typing in right now - there's a usability benefit from having that as managed state (I've lost comments because I closed the wrong tab or accidentally pasted over with something else), and in cases like this there would actually be a privacy concern with doing that on the server side.
In theory you don't need an SPA framework to do that. But in practice SPA frameworks are the only ones that do it well.
There's usability benefit in reloading to reset state and it's the common expectation when browsing. Regardless, if you do decide to add it then its a few lines of code to persist all forms on the page.
SPAs don't automatically provide any state management, and often the complexity requires even more work to manage forms. This is the complaint here, taking a simple requirement and forcing a webapp into it. It's completely unnecessary.
1 reply →