Fork me on GitHub
#shadow-cljs
<
2019-11-25
>
chancy01:11:47

What might the shadow-cljsjs shim look like for a library that only calls (.getSelection js/rangy) and (.init js/rangy)?

lilactown06:11:06

I think you can pretty much npm i rangy and then in a file: cljsjs/rang.cljs

lilactown06:11:36

(ns cljsjs.rangy
  (:require ["rangy" :as rangy])

(set! js/rangy rangy)

chancy01:11:15

I was attempting to try out in a shadow-cljs project.

lilactown06:11:20

trying to import some es6 code on the classpath

lilactown06:11:31

importing clojure_lexer.js fails

lilactown06:11:46

RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.

INTERNAL COMPILER ERROR.
Please report this problem.

null
  Node(NAME LexicalGrammar): repl_interactor/webview/clojure_lexer.js:2:19
let toplevel = new LexicalGrammar();
  Parent(NEW): repl_interactor/webview/clojure_lexer.js:2:15
let toplevel = new LexicalGrammar();

  Node(SCRIPT): repl_interactor/webview/clojure_lexer.js:1:0
import { LexicalGrammar } from "/repl_interactor/webview/lexer.js";
  Parent(ROOT): [source unknown]

thheller11:11:11

don't ever cut errors off please ... always include the full stacktrace. even if it looks like garbage. INTERNAL COMPILER ERROR is from the closure compiler ...

thheller12:11:23

it compiles fine for me btw

thheller12:11:39

but it does have issues when loading and using :es6 output or above

lilactown17:11:53

hmm, I thought I had to use :es6 output to consume ESM from the classpath?

lilactown17:11:23

I moved all the JS code into a separate folder and used npm link instead of putting it on the classpath, which seems to work

thheller20:11:36

the issue is with class

thheller20:11:59

that has its own scoping rules so it is not accesible from other files when using the debug loader

thheller20:11:16

setting :es5 will transpile class out so it works fine then

conan10:11:31

Just thought I'd report back on my experience of running a shadow-cljs REPL with Cursive. After being pointed in the right direction (thanks!) I'm running this script:

(require
  '[orchestra.spec.test :as stest]
  '[shadow.cljs.devtools.api :as api]
  '[shadow.cljs.devtools.server :as server])
(server/start!)
(api/watch :app)
(api/repl :app)
(stest/instrument)
This starts and restarts the compilation in my REPL with a single click. There's a lot of output at startup, but just the compilation result under normal operation. The backend (clojure) half of the application runs in a regular REPL and is used to serve the compiled files, so I'm not using the built-in webserver. My non-Cursive colleagues can easily start a REPL with npx shadow-cljs watch app, although we haven't yet tried cider jack-in. I'm very happy with this setup, compilation is extremely fast (this is often a problem with WSL, figwheel is much worse) and the dev workflow has to be one of the best available in any language.

👍 1
👀 1
grounded_sage11:11:49

How do I access this environment variable?

{...
 :builds
 {:app
  {:target :browser
   :output-dir "public/js"
   :closure-defines {app.core/URL #shadow/env "APP_URL"}
   ...}}}

grounded_sage11:11:56

(js/console.log "This is the URL: " shadow.env/URL) This is where my current thoughts are but I can't seem to figure out how I am supposed to access it.

thheller11:11:13

@grounded_sage you'd have (goog-define URL "some-default") in app.core and access that like any other (def URL ...) in that ns

grounded_sage11:11:11

Oh ok. Maybe I asked that the wrong way. I'm trying to access .env variables during a CI build. Or do the --config-merge thing. But I'm sure how I then access that in the app. I was just defining inline to test accessing it.

grounded_sage11:11:42

I think I get it now though

thheller11:11:50

the browser doesn't have environment variables so you can't access them dynamically

thheller11:11:07

I typically recommend staying away from environment variables entirely

thheller11:11:31

you don't need them .. much better to properly configure your app at runtime

thheller11:11:51

that is really a blog post I should write ... this question comes up so often

grounded_sage11:11:43

Yea I've been reading through discussions on Github issues and old slack messages. It's not super clear to me even from that haha

g7s15:11:35

Has anyone any problems with react hooks and shadow? I can’t for the life of me figure out what is wrong with react giving me this error https://reactjs.org/warnings/invalid-hook-call-warning.html

g7s15:11:58

I have put up a super simple example that reproduces it

g7s15:11:11

I am not sure that it has anything to do with shadow though

g7s15:11:13

just asking

g7s15:11:27

also I’ve found this issue that maybe is related (again not sure) https://github.com/thheller/shadow-cljs/issues/516

thheller16:11:58

@g7s the issue is that you are calling (Test). that is invalid you must create a react element for that instead. so (r/createElement Test #js{}) or so

thheller16:11:44

and not nothing to do with shadow-cljs, just react

g7s16:11:21

@thheller thanks a lot that was it

g7s16:11:29

I guess its not my day 😛

Derek Passen17:11:05

Is there anyway to configure which routes hit the dev-server reverse proxy and which fallback to index.html?

thheller20:11:47

@dpassen1 no. for more complex cases I'd advise using an actual proxy that is made for that stuff 😛

Ian M20:11:03

We ended up overriding the :handler of the dev-server to conditionally proxy requests based on URI: https://gist.github.com/ian-moore/ddf9019f713e10dc5b62e065d0fcc8fc

👍 1
kenny21:11:19

Tried updating from shadow 2.8.67 -> 2.8.74 and I get this console warning logged:

js.js:74 shadow-cljs - failed to load module$node_modules$react_calendar$dist$entry
This prevents a required npm dep from loading causing the app to crash. Is there some new configuration required to get the latest shadow-cljs to work? I have tried rm -rf .shadow-cljs as well, which does not fit it.

thheller21:11:48

what is the rest of the error?

kenny21:11:56

js.js:74 shadow-cljs - failed to load module$node_modules$react_calendar$dist$entry
shadow.js.jsRequire	@	js.js:74
shadow.js.require	@	js.js:100
eval	@	/js/cljs-runtime/com…nents.calender.js:4
goog.globalEval	@	main.js:836
env.evalLoad	@	main.js:2216
(anonymous)	@	main.js:3060

thheller21:11:01

there should be more .. with the actual error at the bottom

kenny21:11:23

There's a separate line that has this:

failed to load compute.ui.components.calender.js Module not provided: ./Calendar.css
env.evalLoad @ main.js:2218
(anonymous) @ main.js:3060

kenny21:11:35

Then a bunch of React errors.

thheller21:11:44

yeah, all triggered by that

thheller21:11:58

I fixed that in master

kenny21:11:38

Oh ok. Best to just stay on 2.8.67 for now?

thheller21:11:49

hang on. I can make a release with the fix

1
thheller21:11:39

2.8.75 should be ready to go

kenny21:11:08

Fixed it! Thanks.

thheller22:11:39

hmm looks like that release is bad .. some AOT issue

thheller22:11:43

2.8.76 in case you get some errors related to goog.define can't explain why that broke in the last release but AOT was behaving strangely before

1
thheller23:11:15

anyone around using shadow-cljs in a somewhat large app? especially those with lots of namespaced keywords? I added a few new compiler tweaks and would like to collect some before/after numbers regarding code size