Fork me on GitHub
#shadow-cljs
<
2023-05-10
>
kennytilton16:05:42

I am trying to come up with a shadow build of a Web/MX app currently built/run with figwheel.main. This shadow https://github.com/shadow-cljs/quickstart-browser is perfect, but it does not actually do anything but present the index.html as is. The missing bit is where our code replaces the "app" , but I guess it goes here, with suitable requires for the goog.* stuff:

(defn init []
  ;; init is called ONCE when the page loads
  ;; this is called in the index.html and must be exported
  ;; so it is available even in :advanced release builds
  (js/console.log "init")
  ;; ---- new code ---
  (let [root (gdom/getElement "app")]
    (set! (.-innerHTML root) nil)
    (gdom/appendChild root
      (gdom/safeHtmlToNode
        (sanitizer/sanitize "<h2>Hi, Mom!!!</h2>"))))
  ;; ---- end new ----
  (start))
In my figwheel stuff that new code is just a top-level form in the core file. Aside: I grok that that only runs once. Web/MX manages DOM dynamically on its own. Not sure what hot reload will bring, but see we will. If that ^^ does not look horrifying

thheller16:05:02

I don't understand your question

thheller16:05:08

> The missing bit is where our code replaces the "app"

thheller16:05:19

what do you mean by that? the quickstart contains everything you need

kennytilton19:05:32

Just getting up to speed slowly. The quickstart never replaces the "app" node, and that step is what I wanted to change. The QS start just logs to the console. If that also was where QS launched its own app, perhaps just to show a SPAN saying "hello app", I would have had the full picture. In hindsight it seems clear. I caught on anyway thanks to this excellent https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html#:~:text=shadow%2Dcljs%20has%20its%20own,is%20very%20much%20the%20same. and I see now I could have replaced the "app" node in the start fn, or had the init fn call my own function that replaces "app". Very nice. Thx! 🙏

thheller16:05:39

this includes the code

thheller16:05:58

this is called when the code is loaded

thheller16:05:26

your code above seems correct?

James Amberger18:05:06

Running npx shadow-cljs on my institutional machine behind a proxy I get

UnknownHostException  <proxy.address:port>: invalid IPv6 address
I'm asking in #C6N245JGG because I have my proxy configured in .m2/settings.xml and that seems to work when I run clj with :mvn deps in another project. npm i also works.Take pity on me, this has ruined my morning. I have attempted to set _JAVA_OPTIONS='-.preferIPv4Stack=true' , this is recognized but doesns't help.

hifumi12318:05:35

Sounds like an issue with the shadow-cljs server starting up behind your company VPN, but there is insufficient information here

James Amberger18:05:18

I think I'm not even reaching the point of starting the server; it fails to download the artifacts from maven

James Amberger00:05:38

@U05224H0W if you want an issue or a doc pr filed mentioning this reason for using clj please let me know; I am happy to provide

thheller18:05:40

you can configure :maven {:proxy ...} in shadow-cljs.edn or ~/.shadow-cljs/config.edn

thheller18:05:51

.m2/settings.xml isn't used I think

James Amberger19:05:53

it seems to be used because my proxy address is showing up in the stack trace, even if I prepend the command with http_proxy= https_proxy=

James Amberger19:05:09

but... it looks like running with clj can be made to defeat this issue

oliver19:05:26

Hi! In my browser project I have a macro that reads a couple of Markdown-files into a map and binds that map to a var. I have marked the namespace using that macro to reload on any change (with :dev/always). That works pretty well except for one thing: changes to the MD-files do not trigger a reload although they're in one of my source paths. I always have to touch one of my cljs files to update the var. Is there any way to have non-`.clj(s)` files watched and trigger a reload?

oliver19:05:21

Aweseome, and quick as always, thanks!

James Amberger19:05:57

Guys amazing thank you