Top
Best
New

Posted by danabramov 4/15/2025

JSX over the Wire(overreacted.io)
267 points | 178 commentspage 2
android521 4/15/2025|
Very well written. It is rare to see these kinds of high quality articles these days.
danabramov 4/15/2025|
Thanks!
wallrat 4/15/2025||
Very well written (as expected) argument for RSC. It's interesting to see the parallels with Inertia.js.

(a bit sad to see all the commenters that clearly haven't read the article though)

jeppester 4/16/2025|
I was immediately thinking of inertia.js.

Inertia is "dumb" in that a component can't request data, but must rely on that the API knows which data it needs.

RSC is "smarter", but also to it's detriment in my opinion. I have yet to see a "clean" Next project using RSC. Developers end up confused about which components should be what (and that some can be both), and "use client" becomes a crutch of sorts, making the projects messy.

Ultimately I think most projects would be better off with Inertia's (BFF) model, because of its simplicity.

dzonga 4/16/2025||
inertia is the 'pragmatic' way. your controller endpoints in your backend - just pass the right amount of data to your inertia view.

& every interaction is server driven.

skydhash 4/15/2025||
Everything old is new again, and I'm not even that old to know that you can return HTML fragments from AJAX call. But this is worse from any architectural point view. Why?

The old way was to return HTML fragments and add them to the DOM. There was still a separation of concern as the presentation layer on the server didn't care about the interface presented on the client. It was just data generally composed by a template library. The advent of SPA makes it so that we can reunite the presentation layer (with the template library) on the frontend and just send the data to be composed down with the request's response.

The issue with this approach is to again split the frontend, but now you have two template libraries to take care of (in this case one, but on the two sides). The main advantages of having a boundary is that you can have the best representation of data for each side's logic, converting only when needs. And the conversion layer needs to be simple enough to not introduce complexity of its own. JSON is fine as it's easy to audit a parser and HTML is fine, because it's mostly used as is on the other layer. We also have binary representation, but they also have strong arguments for their use.

With JSX on the server side, it's abstraction when there's no need to be. And in the wrong place to boot.

danabramov 4/15/2025||
It feels like you haven't read the article and commented on the title.

>The old way was to return HTML fragments and add them to the DOM.

Yes, and the problem with that is described at the end of this part: https://overreacted.io/jsx-over-the-wire/#async-xhp

>JSON is fine [..] With JSX on the server side, it's abstraction when there's no need to be. And in the wrong place to boot.

I really don't know what you mean; the transport literally is JSON. We're not literally sending JSX anywhere. That's also in the article. The JSON output is shown about a dozen times throughout, especially in the third part. You can search for "JSON" on the page. It appears 97 times.

skydhash 4/15/2025|||
From the article:

  Replacing innerHTML wasn’t working out particularly well—especially for the highly interative Ads product—which made an engineer (who was not me, by the way) wonder whether it’s possible to run an XHP-style “tags render other tags” paradigm directly on the client computer without losing state between the re-renders.
HTML is still a document format, and while there's a lot of features added to browsers over the year, we still have this as the core of any web page. It's always a given that state don't survive renders. In desktop software, the process is alive while the UI is shown, so that's great for having state, but web pages started as documents, and the API reflects that. So saying that it's an issue, it's the same as saying a fork is not great for cutting.

React is an abstraction over the DOM for having a better API when you're trying not to re-render. And you can then simplify the format for transferring data between server and client. Net win on both side.

But the technique described in the article is like having an hammer and seeing nails everywhere. I don't see the advantages of having JSX representation of JSON objects on the server side.

danabramov 4/15/2025||
>I don't see the advantages of having JSX representation of JSON objects on the server side.

That's not what we're building towards. I'm just using "breaking JSON apart" as a narrative device to show that Server Components componentize the UI-specific parts of the API logic (which previously lived in ad-hoc ViewModel-like parts of REST responses, or in the client codebase where REST responses get massaged).

The change-up happens at this point in the article: https://overreacted.io/jsx-over-the-wire/#viewmodels-revisit...

If you're interested in the "final" code, it's here: https://overreacted.io/jsx-over-the-wire/#final-code-slightl....

It blends the previous "JSON-building" into components.

skydhash 4/15/2025||
I'm pointing out that this particular pattern (Server Components) is engendering more complexity than necessary.

If you have a full blown SPA on the client side, you shouldn't use ViewModels as that will ties your backend API to the client. If you go for a mixed approach, then your presentation layer is on the server and it's not an API.

HTMX is cognizant of this fact. What it adds are useful and nice abstractions on the basis that the interface is constructed on one end and used on the other. RSC is a complex solution for a simple problem.

danabramov 4/16/2025||
>you shouldn't use ViewModels as that will ties your backend API to the client.

It doesn’t because you can do this as a layer in front of the backend, as argued here: https://overreacted.io/jsx-over-the-wire/#backend-for-fronte...

Note “instead of replacing your existing REST API, you can add…”. It’s a thing people do these days! Recognizing the need for this layer has plenty of benefits.

As for HTMX, I know you might disagree, but I think it’s actually very similar in spirit to RSC. I do like it. Directives are like very limited Client components, server partials of your choice are like very limited Server components. It’s a good way to get a feel for the model.

megaman821 4/16/2025||
With morphdom (or one day native DOM diffing), wouldn't HTMX fufill 80% of your wishlist?

I personally find HTMX pairs well with web components for client components since their lifecycle runs automatically when they get added to the DOM.

pier25 4/16/2025||
What if the internal state of the web component has changed?

Wouldn't an HTMX update stomp over it and reset the component to its initial state?

megaman821 4/16/2025||
Not when using morphdom or the new moveBefore method. Although you would have to give your element a stable id.
pier25 4/16/2025||
Even when using shadow DOM?

What about internal JS state that isn't reflected in the DOM?

megaman821 4/16/2025||
If it is new to the DOM it will get added. If it is present in the DOM (based on id and other attributes when the id is not present) it will not get recreated. It may be left alone or it may have its attributes merged. There are a ton of edge cases though, which is why there is no native DOM diffing yet.
pier25 4/16/2025||
Thanks I need to look closer at this!
whalesalad 4/15/2025|||
to be fair this post is enormous. if i were to try and print it on 8.5x11 it comes out to 71 pages
danabramov 4/15/2025||
I mean sure but not commenting is always an option. I don't really understand the impulse to argue with a position not expressed in the text.
phpnode 4/15/2025|||
it happens because people really want to participate in the conversation, and that participation is more important to them than making a meaningful point.
pier25 4/15/2025||||
Maybe add a TLDR section?
danabramov 4/15/2025||
I don't think it would do justice to the article. If I could write a good tldr, I wouldn't need to write a long article in the first place. I don't think it's important to optimize the article for a Hacker News discussion.

That said, I did include recaps of the three major sections at their end:

- https://overreacted.io/jsx-over-the-wire/#recap-json-as-comp...

- https://overreacted.io/jsx-over-the-wire/#recap-components-a...

- https://overreacted.io/jsx-over-the-wire/#recap-jsx-over-the...

pier25 4/15/2025||
Look, it's your article Dan, but it would be in your best interest to provide a tldr with the general points. It would help so that people don't misjudge your article (this has already happened). It could maybe make the article more interesting to people that initially discarded reading something so long too. And providing some kind of initial framework might help following along the article too for those that are actually reading it.
rwieruch 4/16/2025|||
Feed it to a LLM and let it give you the gist :)
yanndinendal 4/15/2025|||
The 3 tl;dr he just linked seem fine.
pier25 4/15/2025||
the fact that he needed to link to those in a HN comment proves my point...
swyx 4/16/2025|||
it really doesn't. stop trying to dumb him down for your personal tastes. he's much better at this than the rest of us
owebmaster 4/16/2025|||
> he's much better at this than the rest of us

That is not a good reason to make the content unnecessarily difficult for its target audience. Being smart also means being able to communicate with those who aren't as brilliant (or just don't have the time).

retropragma 4/17/2025||
The content isn't difficult. People are just lazy
pier25 4/16/2025|||
> stop trying to dumb him down for your personal tastes

That's unfair.

If anything you're the one dumbing down what I wrote for your personal taste.

pixl97 4/15/2025|||
Yet because of that the issue they were concerned about was shown to the thread readers without having to read 75 pages of text.

Quite often people read the form thread first before wasting their life on some large corpus of text that might be crap. High quality discussions can point out poor quality (or at least fundamentally incorrect) posts and the reasons behind them enlightening the rest of the readers.

retropragma 4/17/2025||
Delegate your thinking to HN comments at your own peril
aylmao 4/15/2025|||
> The main advantages of having a boundary is that you can have the best representation of data for each side's logic, converting only when needs.

RSC doesn't impede this. In fact it improves it. Instead of having your ORM's objects, to be converted to JSON, sent, parsed, and finally manipulated to your UIs needs, you skip the whole "convert to JSON" part. You can go straight from your ORM objects (best for data operations) to UI (best for rendering) and skip having to think about how the heck you'll serialize this to be serialized over the wire.

> With JSX on the server side, it's abstraction when there's no need to be. And in the wrong place to boot.

JSX is syntactic sugar for a specific format of JavaScript object. It's a pretty simple format really. From ReactJSXElement.js, L242 [1]:

  element = {
    // This tag allows us to uniquely identify this as a React Element
    $$typeof: REACT_ELEMENT_TYPE,

    // Built-in properties that belong on the element
    type,
    key,
    ref,

    props,
  };
As far as I'm aware, TC39 hasn't yet specified which shape of literal is "ok" and which one is "wrong" to run on a computer, depending on wether that computer has a screen or not. I imagine this is why V8, JSC and SpiderMonkey, etc let you create objects of any shape you want on any environment. I don't understand what's wrong about using this shape on the server.

[1] https://github.com/facebook/react/blob/e71d4205aed6c41b88e36...

jdkoeck 4/16/2025||
> Instead of having your ORM's objects, to be converted to JSON, sent, parsed, and finally manipulated to your UIs needs, you skip the whole "convert to JSON" part. You can go straight from your ORM objects (best for data operations) to UI (best for rendering) and skip having to think about how the heck you'll serialize this to be serialized over the wire.

I can't let go of the fact that you get the exact same thing if you just render html on the server. It's driving me crazy. We've really gone full circle, and I'm not sure for what benefit.

tshaddox 4/15/2025|||
> The old way was to return HTML fragments and add them to the DOM. There was still a separation of concern as the presentation layer on the server didn't care about the interface presented on the client.

I doubt there were many systems where the server-generated HTML fragments were generic enough that the server and client HTML documents didn't need to know anything about each other's HTML. It's conceivable to build such a system, particularly if it's intended for a screen-reader or an extremely thinly-styled web page, but in either of those cases HTML injection over AJAX would have been an unlikely architectural choice.

In practice, all these systems that did HTML injection over AJAX were tightly coupled. The server made strong assumptions about the HTML documents that would be requesting HTML fragments, and the HTML documents made strong assumptions about the shape of the HTML fragments the server would give it.

skydhash 4/15/2025||
> where the server-generated HTML fragments were generic enough that the server and client HTML documents didn't need to know anything about each other's HTML.

> all these systems that did HTML injection over AJAX were tightly coupled

That's because the presentation layer originated on the server. What the server didn't care about was the transformation that alters the display of the HTML on the client. So you can add add an extension to your browser that translate the text to another language and it wouldn't matter to the server. Or inject your own styles. Even when you do an AJAX request, you can add JS code that discards the response.

rapnie 4/15/2025||
> Everything old is new again

An age ago I took interest in KnockoutJS based on Model-View-ViewModel and found it pragmatic and easy to use. It was however at the beginning of the mad javascript framework-hopping marathon, so it was considered 'obsolete' after a few months. I just peeked, Knockout still exists.

https://knockoutjs.com/

Btw, I wouldn't hop back, but better hop forward, like with Datastar that was on HN the other day: https://news.ycombinator.com/item?id=43655914

tshaddox 4/15/2025|||
Knockout was a huge leap in developer experience at the time. It's worth noting that Ryan Carniato, the creator of SolidJS, was a huge fan of Knockout. It's a major influence of SolidJS.
kilroy123 4/16/2025|||
I was a big fan of knockoutjs back in the day! An app I built with it is still in use today.
csbartus 4/16/2025||
What happened to the very elegant GraphQL? Where the client _declares_ its data needs, and _that's all_, all the rest is taken care by the framework?

Compared to GraphQL, Server Components are a big step back: you have to do manually on the server what was given by default by GraphQL

eadmund 4/16/2025||
> the very elegant GraphQL

The GraphQL which ‘elegantly’ returns a 200 on errors? The GraphQL which ‘elegantly’ encodes idempotent reads as mutating POSTS? The GraphQL which ‘elegantly’ creates its own ad hoc JSON-but-not-JSON language?

The right approach, of course, is HTMX-style real REST (incidentally there needs to be a quick way to distinguish real REST from fake OpenAPI-style JSON-as-a-service). E.g., the article says: ‘your client should be able to request all data for a specific screen at once.’ Yes, of course: the way to request a page is to (wait for it, JavaScript kiddies): request a page.

The even better approach is to advance the state of the art beyond JavaScript, beyond HTML and beyond CSS. There is no good reason for these three to be completely separate syntaxes. Fortunately, there is already a good universal syntax for trees of data: S-expressions. The original article mentions SDUI as ‘essentially it’s just JSON endpoints that return UI trees’: in a sane web development model the UI trees would be S-expressions macro-expanded into SHTML.

moi2388 4/16/2025|||
N+1, security, authorisation, performance, caching, schema stitching..
hyuuu 4/16/2025|||
N+1 is a solved problem at the framework level If GraphQL actually affects your performance, congratulations, your application is EXTREMELY popular, more so than Facebook, and they use graphql. There are also persisted queries etc.

Not sure about caching, if anything, graphql offers a more granular level of caching so it can be reused even more?

The only issue I see with graphql is the tooling makes it much harder to get it started on a new project, but the recent projects such as gql.tada makes it much easier, though still could be easier.

rwieruch 4/16/2025|||
I have been out of touch with the GraphQL ecosystem for a while. What are the status quo solutions to the problems stated above?

N+1 I just remember the dataloader https://github.com/graphql/dataloader Is it still used?

What about the other things? I remember that Stitching and E2E type safety, for example, were pretty brittle in 2018.

YuukiRey 4/16/2025|||
We use the dataloader pattern (albeit an in-house Golang implementation) and it has solved all our N+1 problems.

E2E type safety in our case is handled by Typescript code generation. It works very well. I also happen to have to work in a NextJS codebase, which is the worst piece of technology I have ever had the displeasure of working with, and I don't really see any meaningful difference on a day to day basis between the type sharing in the NextJS codebase (where server/client is a very fuzzy boundary) and the other code base that just uses code generation and is a client only SPA.

For stitching we use Nautilus and I've never observed any issues with it. We had one outage because of some description that was updated in some dependency and that sucked but for the most part it just works. Our usage is probably relatively simple though.

rwieruch 4/16/2025||
Thanks, really appreciate your reply!
hyuuu 4/17/2025|||
if you use node then you have the following for N+1, by having a tighter integration with the database, for ex: https://www.graphile.org/postgraphile/performance/#how-is-it...

or prisma

https://pothos-graphql.dev/docs/plugins/prisma/relations

moi2388 4/16/2025|||
Isn’t every graphql a post, so no http response caching, so you need to do it in-app or with redis?

N+1 and nested queries etc were still problems last I checked (few years ago).

I’m sure there are solutions. Just that it’s not as trivial as “use graphql” and your problems are solved.

Please correct me if I’m wrong

hyuuu 4/17/2025||
it used to be the case that graphql requests are in POST, but not anymore: https://nearform.com/open-source/urql/docs/api/core/#:~:text... example for urql

on top of http level caching, you can do any type of caching (redis / fs / etc) just like a regular rest but at a granular level, for ex: user {comments(threadId: abc, page: 1, limit: 20) { body, postedAt} is requested and then cached, another request can come in thread(id: abc) {comments(page: 1, limit: 20) {body, postedAt} you can share the cache.

N+1 is solved by a tighter integration with the database, for ex: https://www.graphile.org/postgraphile/performance/#how-is-it... or maybe a more popular flavor using prisma: https://pothos-graphql.dev/docs/plugins/prisma/relations#:~:...

but of course, there is always the classic dataloader as well.

I am not saying that use graphql and all the problems will be solved, but i am saying that the problem that OP proposed has been solved in an arguably "better" way, as it does not tie the presentation (HTML) with the data for cases of multiplatform apps like web, or native apps.

csbartus 4/16/2025|||
That's a backend issue I guess ...
5Qn8mNbc2FNCiVV 4/17/2025|||
That's the thing, this brings the benefits of GraphQL without requiring GraphQL (+Relay). This was one of the main drivers of RSC (afaik).

Obviously if you have a GraphQL backend, you could care less and the only benefit you'd get is reducing bundle size f.e. for content heavy static pages. But you'll lose client-side caching, so you can't have your cake and eat it too.

Just a matter of trade-offs

anentropic 4/16/2025|||
Couldn't you have both?

I assumed RSC was more concerned with which end did the rendering, and GraphQL with how to fetch just the right data in one request

hyuuu 4/16/2025||
I was just going to say, all of this has been solved with graphql, elegantly.
spellboots 4/15/2025||
This feels a lot like https://inertiajs.com/ which I've really been enjoying using recently
danabramov 4/15/2025||
Yeah, there is quite a bit of overlap!
tillcarlos 4/16/2025|||
This. We started using it with Rails and it’s been great.

I do like scrappy rails views that can be assembled fast - but the React views our FE dev is putting on top of existing rails controllers have a much better UX.

chrisvenum 4/15/2025||
I am a huge fan of Inertia. I always felt limited by Blade but drained by the complexity of SPAs. Inertia makes using React/Vue feel as simple as old-school Laravel app. Long live the monolith.
chacham15 4/15/2025||
The main thing that confuses me is that this seems to be PHP implemented in React...and talks about how to render the first page without a waterfall and all that makes sense, but the main issue with PHP was that reactivity was much harder. I didnt see / I dont understand how this deals with that.

When you have a post with a like button and the user presses the like button, how do the like button props update? I assume that it would be a REST request to update the like model. You could make the like button refetch the like view model when the button is clicked, but then how do you tie that back to all the other UI elements that need to update as a result? E.g. what if the UI designer wants to put a highlight around posts which have been liked?

On the server, you've already lost the state of the client after that first render, so doing some sort of reverse dependency trail seems fragile. So the only option would be to have the client do it, but then you're back to the waterfall (unless you somehow know the entire state of the client on the server for the server to be able to fully re-render the sub-tree, and what if multiple separate subtrees are involved in this?). I suppose that it is do-able if there exists NO client side state, but it still seems difficult. Am I missing something?

danabramov 4/15/2025|
>When you have a post with a like button and the user presses the like button, how do the like button props update?

Right, so there's actually a few ways to do this, and the "best" one kind of depends on the tradeoffs of your UI.

Since Like itself is a Client Component, it can just hit the POST endpoint and update its state locally. I.e. without "refreshing" any of the server stuff. It "knows" it's been liked. This is the traditional Client-only approach.

Another option is to refetch UI from the server. In the simplest case, refetching the entire screen. Then yes, new props would be sent down (as JSON) and this would update both the Like button (if it uses them as its source of truth) and other UI elements (like the highlights you mentioned). It'll just send the entire thing down (but it will be gracefully merged into the UI instead of replacing it). Of course, if your server always returns an unpredictable output (e.g. a Feed that's always different), then you don't want to do that. You could get more surgical with refreshing parts of the tree (e.g. a subroute) but going the first way (Client-only) in this case would be easier.

In other words, the key thing that's different is that the client-side things are highly dynamic so they have agency in whether to do a client change surgically or to do a coarse roundtrip.

brap 4/16/2025||
Dan, I've been reading some of your posts and watching some of your talks since Redux, and I really love how passionate you are about this stuff. I think the frontend world is lucky to have someone like you who spends a lot of time thinking about these things enthusiastically.

Anyway, it's hard to deny that React dev nowadays is an ugly mess. Have you given any thought to what a next-gen framework might look like (I'm sure you have)?

altbdoor 4/15/2025||
IMO this feels like Preact "render to string" with Express, though I might be oversimplifying things, and granted it wouldn't have all the niceties that React offers.

Feels like HTMX, feels like we've come full circle.

danabramov 4/15/2025|
In my checklist (https://overreacted.io/jsx-over-the-wire/#dans-async-ui-fram...), that would satisfy only (2), (3) if it supports async/await in components, and (4). It would not satisfy (1) or (5) because then you'd have to hydrate the components on the client, which you wouldn't be able to do with Preact if they had server-only logic.
altbdoor 4/16/2025||
Thanks for the reply Dan. That was a great write up, if I might add.

And yeap, you're right! If we need a lot more client side interactivity, just rendering JSX on server side won't cut it.

low_tech_punk 4/15/2025||
The X in JSX stands for HTMX.
danabramov 4/15/2025||
Yes
recursivedoubts 4/15/2025||
unfathomably based
scop 4/15/2025||
I can't help but read this in a baritone blustering-with-spittle transatlantic voice.
nop_slide 4/15/2025|
Just use Django/HTMX, Rails/Hotwire, or Laravel/Livewire
cpursley 4/16/2025||
LiveView is the OG and absolutely smokes those in terms of performance (and DX), but ecosystem is lacking. Anyways, I’d rather use full stack React/Typescript over slow and untyped Rails or Python and their inferior ORMs.
pier25 4/15/2025||
Phoenix/Liveviews

Fresh/Partials

Astro/HTMX with Partials

More comments...