Fork me on GitHub
#clojurescript
<
2021-11-19
>
zendevil.eth07:11:02

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

dazld11:11:22

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

dazld11:11:05

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

dazld11:11:09

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

dazld11:11:41

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

cdeszaq14:11:29

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

dazld17:11:59

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: https://github.com/prestancedesign/pingcrm-clojure/tree/ssr

Arthur03:11:21

I recently wrote a little about some different techniques for pre-rendering reagent+re-frame apps: http://www.arthurbrrs.me/prerendering-react-clojurescript-land.html

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

dnolen13:11:17

@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
borkdude16:11:52

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

#?(:clj
   (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
                                                                                     :no-doc
                                                                                     :doc])})
                                                    (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?

p-himik16:11:00

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.

borkdude16:11:29

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

borkdude16:11:40

I just made it look like one;)

p-himik16:11:05

Ah, right.

p-himik16:11:38

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.

p-himik16:11:33

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.

borkdude16:11:29

an alternative would be to make a cljs specific namespace

p-himik16:11:22

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..

borkdude16:11:37

Yeah, dynaload can handle the nice error

👍 1
p-himik16:11:43

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

borkdude16:11:56

The error is configurable

borkdude16:11:31

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

borkdude19:11:15

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

borkdude@MBP2019 /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 '[foo.foo] :reload)
nil
# newest CLJS
borkdude@MBP2019 /tmp/foo $ clj  -M -m cljs.main -re node
ClojureScript 1.10.893
cljs.user=> (require '[foo.foo] :reload)
Execution error (TypeError) at (<cljs repl>:1).
Cannot read property 'remove' of undefined

borkdude19:11:23

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