Fork me on GitHub
#cljs-dev
<
2021-09-09
>
emccue16:09:31

Reading through the newest DHH rants, wondering if cljs can produce import maps instead of a single bundle

borkdude16:09:42

What are his latest rants?

borkdude16:09:50

What are import maps?

borkdude16:09:54

If you are looking to compile to ES modules, check out the shadow-cljs :esm build, it's the only thing that currently works

emccue16:09:12

more i'm just hoping to escape advanced compilation and all its nonsense

borkdude16:09:33

you could just bypass CLJS by directly using JS you know ;)

😄 2
lilactown18:09:58

CLJS advanced compilation is like lycanthropy: most of the time you don't notice it too much, it gives you abilities that others have to do a ton of work to get in other ways, and every full moon or so it causes a serious problem that only experts understand why it happened

lilactown18:09:10

TBH i'm on team werewolf still

thheller20:09:18

we have :advanced precisely so that we don't have to worry about all the nonsense the JS world is doing 🙂 import maps or esm don't fix those things

💥 2
raspasov01:09:36

@U4YGF4NGM What kind of a rare but serious problem have you encountered from :advanced ? The only problem I’ve ever encountered, I think, is from missing externs.

raspasov01:09:37

… Which granted, is annoying the first 10 times you encounter them 🙂 After than, I learned how to type hint everything properly, and the auto-generated externs take care of that.

lilactown16:09:00

there was the time that names generated via advanced compilations collided with minified code from google analytics 😄

lilactown16:09:44

I am also now very conscious of the fact that static keywords get lifted into a global constants table, after debugging some code that used React's useMemo + a keyword for detecting when it should recompute. turns out the code was buggy, but it wasn't caught in development because a new keyword was being constructed every render; once it went to production, the keyword wasn't constructed every render which triggered the bug

raspasov19:09:43

@U4YGF4NGM Ah, thanks for the explanation. Was the code using references (identical? …) or values (= …) to check if it should re-render?

lilactown19:09:36

usememo compares objects by reference which is why it was breaking in prod (or not breaking in dev)

👍 2
raspasov19:09:26

I’ve had something similar happen when using memoized components where if you have nested components, the inner component would not re-render unless the outer one re-renders

raspasov19:09:30

But I believe it was the same in dev and in prod… so kinda different.

lilactown19:09:05

(let [status (if succeeded? :success :fail)
      ;; recompute something anytime the status changes 
      computed-data (react/useMemo #(expensive-computation data) #js [status])]
  (react/useEffect
    ;; send the data to the API anytime it changes
    #(api/update-state! computed-data)
    #js [compute-state]))
this displays the essence of the problem, though it's reverse - in dev, this will call update-state! every render, since it will reconstruct a new keyword for status every render. whereas in prod it will work as expected

👌 2
dnolen18:09:40

ClojureScript needs advanced compilation

dnolen18:09:52

the analysis is interesting but even for JavaScript you want minification

dnolen18:09:07

however if your usage of JS is precise and you don't need a lot of it, and you tightly control your deps then what DHH is proposing is definitely a big simplification

dnolen18:09:23

we also live in a world where like almost 40% of JS dev is now in TypeScript - so I don't know

dnolen18:09:14

compile steps for JavaScript are never going to go away - and once your application get large enough tree-shaking and minification are must (which DHH largely ignores, but you cannot ignore it)

dnolen18:09:43

if you're waiting a non-advanced compiled ClojureScript - you'll be waiting for a very long time 🙂

lilactown19:09:02

DHH is also a maintainer and advocate of hotwired.dev which is an attempt to move more UI behavior to the backend

lilactown19:09:00

he's on the "tasteful sprinkle of JS" side of things rather than building an entire app in the browser.

lilactown19:09:50

with all the obvious tradeoffs- I've heard mixed reviews of http://hey.com's UI, which uses it