Fork me on GitHub
#shadow-cljs
<
2020-10-04
>
AJ Snow00:10:53

I downloaded the fulcro template to play around with, but I'm getting an net::ERR_CONNECTION_REFUSED whenever I start the server. Has anyone encountered this error before with shadow-cljs? I ask here because the terminal spat out an error that pointed to some shadow-cljs code.

AJ Snow00:10:15

The namespace is shadow.cljs.devtools.client.websocket line 12. Still looking into it though. It seems like anything could cause this which is worrisome.

AJ Snow00:10:30

looking at some of the issues in the github, something with websocket I guess.

AJ Snow04:10:12

redownloading the template caused it to go away. I have no idea why.

victorb10:10:59

Is there any way I can inline the compiled output into the HTML file? Something like HtmlWebpackInlineSourcePlugin but for shadow-cljs

victorb10:10:44

another question, is there a target for generalized JS environment? The context I'm trying to run in is not a browser environment (no access to browser APIs) nor nodejs (so can't use dirname and other nodejs specific things). The environment is a sandboxed browser environment with ES6, with removed browser APIs

victorb11:10:28

more questions, slightly related. There is bunch of extra (undocumented) targets in https://github.com/thheller/shadow-cljs/tree/b05b8f41afd45564ef7b9831a07201d09a5c4a07/src/main/shadow/build/targets, can I use them from the shadow-cljs npm module somehow? I'm not able to figure out how...

thheller13:10:26

@victorbjelkholm429 there is nothing to do the inline the output into html. you could just to it in an extra step after compilation thought. need more information before I can comment on the target thing. Maybe :target :esm does what you need in release mode or any of the node stuff. just don't expect watch or compile to work. release output might work.

victorb13:10:09

Interesting, I'll take a look at the :esm target, thanks! For now, watch/compile for that is not super important, can work around that for now.

victorb13:10:20

for the record, here is where I'm trying to get it to run: https://www.figma.com/plugin-docs/how-plugins-run/ Basically has two different contexts. One "UI" that has access to all the browser APIs but cannot load JS sources via script tags, everything has to be inlined. The other one "code" (basically background) that has no access to browser APIs but custom ones like the figma one. Currently I got the UI one working fine by having shadow-cljs output a npm-module that I'm including in a "vanilla JS" file, then webpack packs it + index.html into a single file with the JS embedded. Having harder time getting the "code" context to work, as output from shadow-cljs (cljs-compiler maybe?) is either assuming it's in a browser OR nodejs context while in "code" context, neither global, process nor window is available

thheller13:10:19

:target :browser may work too, but again just in release

thheller13:10:30

in compile or watch it will definitely try to access all of those

victorb13:10:48

Hm, I'll give release a try, didn't try it before with the :browser target. Thanks for the guidance!

victorb09:10:14

Managed to get it to work by using a combination of compile for the "Figma UI target" and release for the "Figma background target", and using the :browser target for both. Thanks for the help!

thheller09:10:52

the :ui-dev build you do not need

thheller09:10:07

or I guess the :ui build is old since its still :npm-module?

victorb09:10:12

@U05224H0W I do 🙂 I have two different environments, one where I simulate the Figma environment in the browser

victorb09:10:40

has to be a npm module as after shadow-cljs I pass it to webpack to inline UI into the index.html (needed for Figma...)

victorb09:10:50

it's a bit tricky and messy, but it works at least. Basically I shim the APIs that Figma provide in the plugin context, if FIGMA is false. So I can develop most of it in browser, and then only test integration in figma itself

thheller09:10:08

well there could be a :target :figma-plugin or so that takes care of some of the messiness

thheller09:10:15

but I don't have time to look into that currently

victorb09:10:13

@U05224H0W don't worry about it, thanks for the guiding so far. I think it's a pretty small intersection of people who write clojure and writes Figma plugins 😄 I might open source the wrapper I'm using, to help others, and if that sees any interest, I could think about contributing a :figma-plugin target

xfyre21:10:39

Is there a way to make React Native hot reload feature work? Somehow Metro bundler reloads the whole bundle after recompilation

thheller22:10:07

disable it completely and let shadow-cljs handle the reload

xfyre22:10:24

@U05224H0W thanks for the pointer! It works much better (the currently active screen doesn’t refresh though)

thheller22:10:21

you must set up the re-rendering properly

thheller22:10:40

so if nothing refreshes you likely have done something that breaks that or not done it at all

xfyre22:10:18

got it, thank you!

xfyre02:10:21

so now I have

(defn dev-render-root {:dev/after-load true} []
  (shadow/render-root "DcnetApp" (r/as-element [app-root]))
  )
it’s called after I update the code, as expected
[Sun Oct 04 2020 19:17:50.501]  LOG      load JS dcnet_app/screens/home.cljs
[Sun Oct 04 2020 19:17:50.507]  LOG      load JS dcnet_app/appnav.cljs
[Sun Oct 04 2020 19:17:50.508]  LOG      call dcnet-app.ios.core/dev-render-root
but the screen doesn’t get updated. anything else I might be missing?

xfyre03:10:51

I think something’s off with the bundler. I tried two other methods (directly calling .forceUpdate and updating ratom within the root component). It does trigger re-rendering, but still displays old version of the code. I’ll let you know if I figure it out.

thheller08:10:34

check the "things to avoid" and "hooking up react"

xfyre16:10:26

I think I finally made it work, thanks a lot for your help!

thheller22:10:11

otherwise no clue

Galagora22:10:20

Hi. I have a CommonJS module in src/add.js (`module.exports = add`) and this CLJS code in src/habit/core.cljs:

(ns habit.core
  (:require [moment]
            ["/add" :as add]
            ))

(println (add 1 2))
(defn main []
  (println "hi"))
With this shadow-cljs.edn:
{:source-paths
 ["src/"]

 :dependencies
 []

 :builds
 {:m
  {:target :node-script
   :main habit.core/main
   :output-to "out/core.js"
   }}}
I then run sc cljs-repl m and node out/core.js which outputs "3" and "hi". However, in the repl, I get this error when trying to access add : #object[ReferenceError ReferenceError: module$add is not defined] . I can access moment fine. What am I doing wrong?

Galagora22:10:16

Should I try an earlier one?

thheller22:10:45

no. just ruling out that you are on old versions 😛

thheller22:10:24

might just be a bug in the node-repl. don't really know. not something alot of people do