Fork me on GitHub

What’s the best way to do server-side-rendering as in next.js for cljs?


honestly, never tried doing ssr of reagent or similar components in cljs - but can imagine it’s very similar


hiccup - in theory - has a compelling cross platform aspect. it’s just data, right?


in practice though, the cljs apps aren’t just hiccup, but have behaviour.. it’s a bit of a mess. with discipline or the correct library, there’s no reason why hiccup producing functions can’t be used both server side, and on the client


to be specific - things like hooks that load data would need abstracting so they are platform agnostic


We’ve had some success using cljs as the “guts” of our apps with vanilla React at the outer layer to handle the SSR coordination parts. It works fairly well, since it is all JS at runtime


thats a neat idea.

Michaël Salihi20:11:54

You can maybe take a look at the SSR branch of this full stack project that I open sourced. It uses Inertia.js for wire the front and the back end:


I recently wrote a little about some different techniques for pre-rendering reagent+re-frame apps:

Colin P. Hill12:11:51

Anyone know of a relatively simple and tidy Om Next example repository? Got some legacy code I need to wrap my head around, and think it might help to first wrap my head around something less complex


@ps the percentage of usage in the survey hasn't really changed ~3% over time, so I would say less declining rather it's just not that interesting of an option for mainstream JS dev - many people are aware that it exists - w/o having ever used it far as I can tell

✔️ 1

I have this macro. I want to make the cljs.analyzer.api optional for those who only use this library on the clojure JVM:

   (defmacro copy-ns [ns-sym sci-ns]
     (macros/? :clj `(copy-ns-fn (ns-publics ~ns-sym) ~sci-ns )
               :cljs (let [publics-map (cljs.analyzer.api/ns-publics ns-sym)
                           publics-map (zipmap (map (fn [k]
                                                      (list 'quote k))
                                                    (keys publics-map))
                                               (map (fn [m]
                                                      {:name (list 'quote (:name m))
                                                       :val (:name m)
                                                       :meta (select-keys (:meta m) [:arglists
                                                    (vals publics-map)))]
                       ;; (prn publics-map)
                       `(copy-ns-fn ~publics-map ~sci-ns)))))
Should I do this using the usual means of trying to resolve the cljs.analyzer.api + a try catch or so?


Isn't it already optional with this code? The :cljs branch won't be included in the CLJ code at all, so the NS won't be needed.


Note that macros/? is borrowed from macrovich, it's not a reader conditional


I just made it look like one;)


Ah, right.


The :cljs "branch" then needs to explicitly require the cljs.analyzer.api namespace. And yeah, I would go with try-catch. At least then you can print out a reasonable error and not make it implicit, where it would fail for some but work for others that happened to require that ns some place else.


I can't think of any reason why you wouldn't want to do that, or of any other reasonable way to achieve the same outcome.


an alternative would be to make a cljs specific namespace


Hmm, right. FWIW, from a user's perspective I would rather have an exception tell me what I forgot to add than to see Could not locate cljs/analyzer/api__init.class, cljs/analyzer/api.clj or cljs/analyzer/api.cljc on classpath..


Yeah, dynaload can handle the nice error

👍 1

An extra +1 to the niceness if the error can also tell what lib exactly needs to be added to have that namespace available. :)


The error is configurable


Kind of. You can provide a default, so you an provide a function that upon usage throws a nice error message at you


I think I may have run into a bug here with :reload?

[email protected] /tmp/foo $ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.879"}}}' -M -m cljs.main -re node
ClojureScript 1.10.879
cljs.user=> (require '[] :reload)
# newest CLJS
[email protected] /tmp/foo $ clj  -M -m cljs.main -re node
ClojureScript 1.10.893
cljs.user=> (require '[] :reload)
Execution error (TypeError) at (<cljs repl>:1).
Cannot read property 'remove' of undefined


Is it possible to see with cljs.analyzer.api/ns-publics if a macro is available with self-hosted or only for JVM Clojure?