This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-20
Channels
- # adventofcode (17)
- # announcements (1)
- # aws (1)
- # beginners (102)
- # calva (27)
- # cider (16)
- # clj-commons (34)
- # clj-kondo (33)
- # cljs-dev (5)
- # cljsrn (4)
- # clojure (124)
- # clojure-europe (17)
- # clojure-nl (8)
- # clojure-spec (13)
- # clojure-uk (6)
- # clojurescript (68)
- # datahike (21)
- # datomic (23)
- # emacs (3)
- # fulcro (30)
- # introduce-yourself (6)
- # jobs-discuss (6)
- # lsp (31)
- # nextjournal (3)
- # off-topic (1)
- # other-languages (45)
- # portal (4)
- # re-frame (8)
- # releases (4)
- # shadow-cljs (39)
- # specter (6)
- # tools-build (18)
- # tools-deps (11)
Any idea what is going on here? Works fine in dev mode, but once you compile it the modules seem to break: https://nyancad.github.io/Mosaic/app/editor.html Source: https://github.com/NyanCAD/Mosaic
Well if you look at the inspector when opening the page it says "Uncaught TypeError: $APP.qr is undefined"
Ah, that page already has a deployed release app, right?
The JS console has this on my end: Cannot read properties of undefined (reading 'prototype')
.
That should be easy to track. In your case, the error is even more clear. I'm 90% certain it's due to externs. During dev builds, the compiler leaves x.someLongName
just as that, and during a release build it may turn into something like x.qr
if the compiler isn't told that someLongName
should not be renamed because e.g. it comes from some thirdparty library or from data.
This is a nice article on externs: https://code.thheller.com/blog/shadow-cljs/2017/11/06/improved-externs-inference.html
Welp you're getting a different error? đ
Ah chrome gives that error
Same line though
The real error seems to be the same - something is undefined. Maybe we have different versions of Chrome, maybe different flags, maybe different OSes.
So one surprising thin is that if you search for $APP.qr
in https://nyancad.github.io/Mosaic/app/js/common.js it's actually in there.
Since this started happening after I split up editor.js
and common.js
into modules, I'm kinda inclined to think it's something weird about the module part.
So just add :compiler-options {:infer-externs :auto}
? Lemme try.
Not "just" - you will have to change the source code at places where shadow-cljs complains. The relevant documentation section: https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs
Well it does not complain as far as I can tell
Hmm, no clue then. If you don't know where exactly you need to put ^js
and shadow-cljs doesn't tell you where it can't infer externs, maybe there's some issue with externs inference when it comes to projects with multiple modules. If so, I'd try creating a minimal reproducible example and asking in #shadow-cljs
ah wait..
Yea no... I thought I had put the thing in the wrong place but... no change
I'm not sure it's related to externs, as the common.js file actually does include the name it's trying to use, so something weird is going on
And that "there" might not be the right "there". :) But it can indeed potentially be something unrelated to externs. But I don't think I've ever seen an issue that was manifesting itself only in the release build that wasn't about externs.
So on line 2977 of common.js it says $APP.qr.prototype.Xa=function(){return this}
so... yea that's why I'm not sure why it'd be related to externs, because the names in the two modules seem to match up.
Could it be some setup function that's not called or something, leaving it undefined?
Yep. Which, in turn, can be a consequence of externs not being inferred correctly somewhere. :) It's impossible to guess, you would have to debug it.
Just not sure where to start debugging.... I guess I can try to undo the modules and see if that solves it. Are externs used between modules, or only between cljs and js code?
No clue. Regarding debugging - you can try intermediate optimization methods and see if that solves it. You can also try following the code and the values back up the stack from the error while comparing the working and the non-working versions side-by-side.
Hmyea simple optimizations makes it work soooo :thinking_face:
But making it a complete build instead of modules resolves the problem too, so it something about the interface between the modules that's the problem
Is there a cljs equivalent to clj's System/getenv
? I'm targeting the browser so I assume not.
Browser apps don't really deal with environment variables. Query parameters tacked on the URL of your browser app may be an option to pass in stuff like that. What problem are you trying to solve?
you can use environment variables at build time though, I donât have much cljs experience but that s a common pattern in elm/js/ts to feed like API urls and other stuff that differ from localhost to staging to prod.
we are having just a constant nightmare with figwheel and knowing if we actually have the latest version of code
so we are thinking of just adding an optional flag for devs where we use speech synthesis to literally say out loud âLoaded code compiled at twelve fourty five pmâ
there should be logs in the console when code reloads? at least that's what shadow does
Hmm, but that would be refreshed on each page load or re-render of the parent component.
You can probably replace (js/Date.)
with a macro that returns the current time.
you have reload hooks for figwheel. have it play a quick sound. a previous job of mine did that
i know reload hooks exist, i just dont know how to get the time last compiled/reload triggered into that
If a reload hook is executed if and only if a compilation was successful, why not just get the current time right there in the hook?
I know this isn't what you're asking, but this does sound like trying to treat a broken ankle with a bandaid. if I was working on that project, I would probably clamor to investigate those really long compile times
I work on an app that is close to that size and I only see those kinds of reload times when changing things at the very root of the dependency tree (which is very rarely). if the generic (perhaps ill fitted) advice I gave in the channel doesn't speak to your situation, then I guess we're making lemonade.
I know that fig wheel has (perhaps used to have) :recompile-dependents
and :reload-dependents
on by default, which can dramatically slow things down depending on the size and shape of your project. Take a lookhttps://figwheel.org/docs/hot_reloading.html, by turning one or both off you may fix your problem.