Replicant takes this idea and runs with it, narrowing it down even further: The function is a pure function that returns the new UI as data. Replicant uses this representation to update the DOM accordingly.
That’s it. No partial updates, no mutable objects, no network activity from UI components. It’s basically a templating system. You give it data, and it returns a view. Whether that data comes from a DB or any other place, it's just a clojure data structure. Here is the article that most of this comment is lifted from: https://replicant.fun/top-down/
So, is the main difference that replicant is not built on top of react?
> When using a Content Security Policy (CSP), unsafe-eval must be allowed for scripts, since Datastar evaluates expressions using an IIFE (Immediately Invoked Function Expression).
The project itself links to Mozilla’s docs on CSP, which state:
> The unsafe-eval keyword can be used to override this behavior, and as with unsafe-inline, and for the same reasons: developers should avoid unsafe-eval.
Out of the box, htmx uses a similar approach, but one can disable this use of eval [2]:
htmx.config.allowEval - can be set to false to disable all features of htmx that rely on eval:
- event filters
- hx-on: attributes
- hx-vals with the js: prefix
- hx-headers with the js: prefix
[1]: https://github.com/starfederation/datastar/blob/develop/site...It's not a problem in practice, just ensure to use HTTP/2.
1. Client-heavy state management (separate client application)
2. Client-light state management (thin client)
The state has to be tracked and managed somewhere. In most web applications, that state is persistable - at some point, it will end up in a DB of some kind.
As such, we already have to handle it on the server side, regardless of whether we also choose to separately manage it on the client side or not.
So the question at the end of the day is: Do I want to separately manage the application state on the client side, when I am already managing it on the server side?
In a lot of situations, the pragmatic answer would be "No". Why? Because managing the state in two places causes duplication, synchronisation issues, diverging logic issues, and so on. We are increasing the accidental complexity of our solution. Maintainability becomes slower, riskier and more expensive.
For some applications, the extra complexity might be worth it. In most web applications I have worked with (eCommerce, internal business tools, booking systems, online calculators, business dashboards), it is not.
And "let's keep all state and processing on the server" does not anymore mean no real-time or highly interactive features. With SSE and fast HTML fragment merging, we can enjoy highly interactive and performant web applications with almost no client-side application state management.
Assuming you are using Datastar the way I do with a single persistent SSE connection.
This feature is also much better for the battery life of devices and the server as you are only sending stuff if the user is there.
Spotty connection - no problem, SSE reconnects.
- The server is in Europe. - The process can be modified at the REPL while It's running (and the changes get pushed out to all users by the SSE). So the board, HTML, CSS etc can all be changed on the fly without a restart.
The initial bundle is 12kb (datastar + initial html + css). What you are seeing is the constant SSE connection streaming compressed data.
Are you behind a corporate proxy? Also what version of firefox? Because it's working fine on firefox for me?
With .cljc files you can avoid the duplication anyway.
This is why I will never touch something like React, a self inflicted wound.
Even Datastar/HTMX might be too much. Server-side HTML can get you very, very far in most applications. It's faster, lighter, and looks and feels cleaner.
Case in point: do you really prefer a heavy, real time interactive message board like the default interface of Reddit? Because we're talking on HN, which is super fast, light, usable, and completely server-side.
HTMX is real time in the sense that it updates over the wire, but you're still keeping all state on the server side.
I don't want to reload the page to open a drawer. You'll notice HN isn't exactly mobile friendly because that requires hiding enough options that you need drawers or other ways to shrink and expand. You can do that with CSS, but that's still state, just state localized to that page load.
And there are sites that have unavoidably complex session state. You can have a resource that's on half the pages but is expensive to compute. I don't want to load it every time when almost none of it changes. I don't want to cache it on the server if it's a big payload
There's a world of difference between no state and over bloated SPAs