This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-16
Channels
- # announcements (2)
- # beginners (25)
- # calva (50)
- # cider (33)
- # clj-kondo (46)
- # cljs-dev (5)
- # cljsrn (23)
- # clojure (34)
- # clojure-dev (5)
- # clojure-russia (2)
- # clojure-spec (29)
- # clojurescript (11)
- # datomic (3)
- # docker (2)
- # duct (1)
- # emacs (11)
- # fulcro (15)
- # jobs-discuss (47)
- # off-topic (11)
- # om (2)
- # pathom (6)
- # re-frame (9)
- # reitit (4)
- # remote-jobs (1)
- # shadow-cljs (105)
- # spacemacs (4)
- # tools-deps (6)
- # xtdb (4)
It seems like the manifest.edn should not be generated in the same place as the target output, because the target output needs to be public, but it seems that the manifest.edn should not
Hello, new to shadow-cljs; I'm in the process of migrating an application over from figwheel-main and am encountering an error with the npm module viz.js https://www.npmjs.com/package/viz.js. viz.js is an Emscripten transpile of graphviz (which is C) to asm javascript so the javascript itself (in full.render.js in the viz.js package) is pretty hairy!
I follow the instructions at the bottom of the viz.js author's page https://github.com/mdaines/viz.js/wiki/Usage and the shadow-cljs user guide (section 11) and require viz.js into my code as so
Caused by: RuntimeException: INTERNAL COMPILER ERROR. Please report this problem. An enclosing scope is required for change reports but node LABEL 15 [length: 2] [source_file: node_modules/viz_DOT_js/full.render.js] doesn't have one. Node(FOR): node_modules/viz_DOT_js/full.render.js:15:4095
so, not really needing viz.js to be attempted to be further compiled, I set the following option in my shadow-cljs.edn
but unfortunately this seems to cause breaks around other existing dependencies in my project, for example [io.nervous/kvlt "0.1.4"]
Any tips on how to get this particular npm module to work (as an npm module) would be much apprecicated.
@mojo yeah the emscripten packages seem to confuse the closure compiler. :js-provider :require
is only for node
environments and doesn't work in the browser.
for viz you probably need to stick with https://github.com/mdaines/viz.js/wiki/Usage#using-a-script-tag for now
it used to be compilable though https://github.com/thheller/shadow-cljs/issues/173
Got it - thanks for the steer. Yes - as the description says it's a (clever) hack š I also have Graphviz mounted as an AWS lambda but then realised that sending my company's data out over the web is not policy compliant hence the need for the hack! Would be supportive of the option to provide a list of modules which don't go through any compilation processing.
One other thing to mention. I had also tried the approach of requiring the .js files as set out in section 11.2 of your excellent documentation, but had no luck with that approach - it couldn't find the modules even though I'd followed the suggested directory structure. Is that approach also only for the
node
environments? If so, as a newbie coming to the documentation, that wasn't immediately obvious to me and could well be worth clarifyingyes - requiring as a node module. Well, when that didn't work and before posting here, I always tried the approach laid out in section 11.2.1 of your documentation - requiring the js files correctly. The reason I tried that as well was that pretty sure I read there that any source .js files under a js/ would not be passed through compilation
so wondered alternative approach is valid for the :browser target? (and I just hadn't got it quite right) - or only for other targets?
no that is incorrect. quite the opposite actually. the files will go through :advanced
optimizations
node_modules
will only do :simple
which already fails for viz.js
so :advanced
is unlikely to work
The line that confused me was actually in the following section 11.2.3 - Notice how src/js is not added to :source-paths and will not be added to the classpath. Obviously, I must have speed read too much and jumped ahead thinking that between the two sections, there was a way to exclude .js files from the compiler but still be able to require them. my bad. thanks for clarifying
Iām trying out that weird trick mfikes posted in #cljs-dev:
(do (declare ^{:arglists '([a b c] [a b & cs])} create-element)
(set! create-element react/createElement))
and currently seeing this warning during compilation:
18 | (defn tag-render [{:keys [title body]}]
-------^------------------------------------------------------------------------
Wrong number of args (5) passed to hiccup-next.react/create-element
--------------------------------------------------------------------------------
19 | #h/n [:div {:class "card"}
20 | [:div {:class "card-title"} title]
21 | [:div {:class "card-body"} body]
22 | [:div {:class "card-footer"}
--------------------------------------------------------------------------------
yes, no custom reader tags during compilation. at runtime is fine but not during compilation
hmm. I was getting some issues with the reader tags at first. I was able to work around it by having the CLJS namespace require the macro namespace
hereās my current experiment: https://github.com/Lokeh/thumps
the issue is that you are doing things during read-time. so you basically have to turn of caching since it impossible to tell what its going to do
hmm. is there a significant difference between doing things at read-time vs. macro-time from the perspective of caching?
(ns my-app.core
(:require [hiccup-next.core]
[hiccup-next.react :refer [<>]]))
(defn Mycomponent [props]
(let [name (goog.object/get props "name")]
(<> [:div {:style {:color "green"}}
[:span "Hello, " name]
[:ul
(for [n (range 10)]
(<> [:li {:key n} n]))]])))
(react-dom/render (<> [MyComponent {:name "Sydney"}])
(. js/document getElementById "app"))
the difference with read-tags versus macros is that their dependency is never declared in the code
so by looking at the ns form you can't tell that the namespace is gonna use hiccup-next.react
unless you require it
I am starting to see the tradeoffs yes Iām just still not sure about your mention of caching. probably my naivety about how shadow-cljs works
honestly itās just an experiment. I kind of like the aesthetics of #hiccup
vs (hiccup)
and it allows you to seamlessly do things like shove elements over the wire and back (which is something weāre doing at work atm in a different way)
your code doesn't declare that is depends on something and therefore won't be invalidated if that something changes
ah, unless they register a new element keyword e.g. (register-element! :my-app/foo FooComponent)
ā¦
actually that would be in the react namespace which is required everywhere itās used
although itās still global mutable state in a macro namespace so would probably still have issues
the one concrete thing I think I like about #h/n ...
vs (h/n ...)
is ease of typing š I basically write hiccup like I have been trained with Reagent / hx, then stick the tag on the beginning at a few places and Iām done
I need a bunch of time stuff so I naturally added things like #time/duration {:minutes 30}
etc
until it got a total maintenance disaster and caused all sorts of weird issues with AOT
I started down the road of creating a CLJ implementation of React string rendering againā¦ then got frustrated and gave up for now
I was telling roman01la that I think it would be really nice to have a react.clj
lib that was separate from a specific hiccup library / ui framework like rum
/ hx
/ uix
/ etc.
that would take some normalized format {:type "div" :props {...}}
and implement turning those trees into an HTML string
and then the rest of us can muck about with syntax / macros / extensions and processing on top of it instead of copying + pasting and rewriting the same code
haha, well I think either way we have to write the code to cover those corners š just Reactās already done it in the browser for us!
I am seeing a clear benefit of separating hiccup and the underlying rendering engine (whether it be Reactās VDOM or something else)ā¦ thereās lots of different things we can do to improve the hiccup syntax experience, extensions, etc. that doesnāt really have anything to do with rendering HTML
otherwise is just changing (:require [hiccup-next.react :refer [<>]])
to (:require [[something.else :refer [<>]])
right! and separating the syntax from the engine that actually produces the resulting HTML/JS allows others to extend the semantics further without breaking compatibility with the engine
put another way, we could build that semantic on top of React and it would continue to work with other React components once parsed & compiled
one of the reasons people have asserted that React isnāt needed and is inefficient is because we have hiccup. that we should use hiccup, instead of Reactās VDOM
and I was kind of on board with this argument for awhile, but now I think that coupling the syntax we use for writing code to the rendering engine is probably bad