Fork me on GitHub
#clojurescript
<
2021-12-20
>
Pepijn de Vos13:12:08

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

p-himik13:12:31

What do you mean by "seem to break"?

Pepijn de Vos13:12:13

Well if you look at the inspector when opening the page it says "Uncaught TypeError: $APP.qr is undefined"

p-himik13:12:50

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.

Pepijn de Vos13:12:07

Welp you're getting a different error? 😞

Pepijn de Vos13:12:40

Ah chrome gives that error

Pepijn de Vos13:12:56

Same line though

p-himik13:12:01

The real error seems to be the same - something is undefined. Maybe we have different versions of Chrome, maybe different flags, maybe different OSes.

Pepijn de Vos13:12:13

My error is on Firefox so yea

👍 1
Pepijn de Vos13:12:36

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.

Pepijn de Vos13:12:24

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.

p-himik13:12:31

Have you tried the approach from the article I linked?

Pepijn de Vos13:12:23

So just add :compiler-options {:infer-externs :auto} ? Lemme try.

p-himik14:12:52

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

Pepijn de Vos14:12:20

Well it does not complain as far as I can tell

p-himik14:12:40

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

Pepijn de Vos14:12:36

Yea no... I thought I had put the thing in the wrong place but... no change

Pepijn de Vos14:12:29

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

p-himik14:12:04

The name $APP.qr might be there and still be undefined.

p-himik14:12:31

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.

Pepijn de Vos14:12:20

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.

Pepijn de Vos14:12:54

Could it be some setup function that's not called or something, leaving it undefined?

p-himik14:12:49

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.

Pepijn de Vos14:12:25

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?

p-himik14:12:47

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.

Pepijn de Vos14:12:52

Thanks, I'll see what I can do 🙂

👍 1
Pepijn de Vos14:12:04

Hmyea simple optimizations makes it work soooo :thinking_face:

p-himik14:12:37

So it's probably about names, yeah.

Pepijn de Vos14:12:36

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

p-himik14:12:10

Then I'd definitely ask in #shadow-cljs given how much it's tool-specific.

dnolen18:12:29

of interest is fixing Firebase 9.X.X usage

🙂 2
Chase22:12:50

Is there a cljs equivalent to clj's System/getenv ? I'm targeting the browser so I assume not.

Chase22:12:34

I'm using shadow-cljs so maybe that's where I should be looking, huh?

p-himik22:12:46

Indeed, it's documented.

chepprey01:12:38

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?

LĂ©o J07:12:17

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.

Chase13:12:13

Yeah I used shadow-cljs to handle it. Thanks folks

emccue22:12:31

What is the best way to get the “time the last compile ran”

emccue22:12:52

we are having just a constant nightmare with figwheel and knowing if we actually have the latest version of code

emccue22:12:32

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”

lilactown22:12:37

there should be logs in the console when code reloads? at least that's what shadow does

lilactown22:12:55

I would imagine it would also show up in the network console

dpsutton22:12:04

i remember a heads up display from figwheel when new code was loaded

dpsutton22:12:21

in the network console it would be over websocket so easier to miss

emccue22:12:52

we never know which reload is actually on screen from the console

emccue22:12:10

and we are in the code window when the reload happens so we miss the graphic

emccue22:12:42

and it is not at all fast. compiles take like a minute

emccue22:12:55

except when they dont

emccue22:12:59

and then the reload triggering takes longer

p-himik22:12:10

Just put [:span (js/Date.)] somewhere? Or something else if you aren't using Hiccup.

p-himik22:12:05

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.

emccue22:12:17

right but if that namespace doesnt change it wont reload

dpsutton22:12:37

you have reload hooks for figwheel. have it play a quick sound. a previous job of mine did that

emccue22:12:48

^see im not crazy

emccue22:12:19

i know reload hooks exist, i just dont know how to get the time last compiled/reload triggered into that

p-himik23:12:27

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?

emccue23:12:15

because the reload can happen after a compilation by a significant delay

emccue23:12:39

so we can make an edit, see a reload, and that wasnt the “right” reload

p-himik23:12:25

Ah, right.

lilactown23:12:24

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

emccue00:12:52

I mean, its not a mystery. there are about 100k lines of cljs and cljc

lilactown01:12:46

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.

lilactown23:12:27

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.