Fork me on GitHub
#shadow-cljs
<
2024-04-23
>
valerauko02:04:07

Is there any example out there for generating web components with shadow-cljs?

thheller06:04:17

I haven't looked at it but it appears to be using web components

valerauko02:04:45

Thanks I'll check those out!

Akiz12:04:05

Hi, I have got same namespaces that works fine with REPL until i reload browser. Once I do i cant create / refer anything in repl for those namespaces. I get error like these: before reload:

some-namespace> (def x 1)
#'some-namespace/x
after reload
some-namespace> (def x 1)
Execution error (TypeError) at (:1).
Cannot set properties of undefined (setting 'x')
:repl/exception!
What is going on?

Akiz13:04:45

This is what I see in dev console

REPL Invoke Exception TypeError: Cannot set properties of undefined (setting 'x')
    at eval (eval at shadow$cljs$devtools$client$browser$global_eval (shadow.cljs.devtools.client.browser.js:1:1), <anonymous>:2:43)
    at eval (eval at shadow$cljs$devtools$client$browser$global_eval (shadow.cljs.devtools.client.browser.js:1:1), <anonymous>:3:1257)
    at eval (<anonymous>)
    at Object.shadow$cljs$devtools$client$browser$global_eval [as global_eval] (browser.cljs:155:5)
    at Object.eval [as shadow$cljs$devtools$client$shared$IHostSpecific$do_invoke$arity$3] (browser.cljs:200:8)
    at Object.shadow$cljs$devtools$client$shared$do_invoke [as do_invoke] (shared.cljs:23:15)
    at shadow$cljs$devtools$client$shared$handle_repl_invoke (shared.cljs:118:14)
    at Object.shadow$cljs$devtools$client$shared$interpret_action [as interpret_action] (shared.cljs:173:16)
    at shadow$cljs$devtools$client$shared$interpret_actions (shared.cljs:208:8)
    at Object.shadow$cljs$devtools$client$shared$continue_BANG_ [as continue_BANG_] (shared.cljs:101:4) Object

thheller15:04:38

The browser is holding the REPL state, if you reload it the REPL state is gone

thheller15:04:57

its your runtime. Same deal in Clojure, if you restart Clojure the REPL state is also gone

thheller15:04:14

So, sounds totally expected to me?

Akiz16:04:24

@U05224H0W I am not sure. This is the scenario: 1. I start repl and run browser 2. I define some variable in repl 3. I reload a browser 4. I can’t define a variable or refer anything until I reevaluate the namespace again. The thing is that this is happening only for some namespaces. When i switch to different namespace in REPL then I can define / refer variables even after browser has been reloaded.

thheller16:04:44

the namespace is gone, if you redefine it everything will be fine

thheller16:04:12

basically you are trying to do x.y =1 but x is undefined

thheller16:04:43

as I said reloading the browser wipes all runtime state. there is still some server-side state that "knows" the namespace, but the relevant runtime is gone

Akiz16:04:17

But why I can do z.y = 1 and not x.y = 1 ?

thheller16:04:21

because z is defined? I guess

thheller16:04:41

this is all a bit abstract. if you give me more details about your setup I can give more precise answers

thheller16:04:22

could be that z is part of the namespaces defined by your regular build

thheller16:04:27

but x is not and therefore undefined

thheller16:04:36

all I can do is guess 😛

Akiz16:04:38

Ah, right, I see what’s going on. Thank you very much, I’ve adjusted the loading / eval of namespace as I need and it works now. Surprisingly, I haven’t encountered this until now :-)

Akiz18:04:24

@U05224H0W Why I see a different error there? What is it telling me?

thheller18:04:14

same thing as before?

Akiz18:04:42

I don’t reload browser or anything like i did

thheller18:04:55

warnings in general mean that the code may not act as you expect it to

thheller18:04:07

so get rid of warnings and do NOT assume stuff will work after you got a warning

thheller18:04:28

so please isolate the first error from the clean fresh state

thheller18:04:45

I cannot comment on 5 different warnings when everything is already in a broken state as far as I can tell

thheller18:04:38

also which shadow-cljs version do you use? there was a bug that sometimes require didn't set up aliases properly

Akiz18:04:07

@U05224H0W I use 2.27.1 1. the first warning is coming from Flowstorm - I got rid off it 2. the second one appears once i require Portal The thing is that Portal isn’t in deps.edn dependencies but it can be required. How I got into this state?

Akiz18:04:45

This is I why also attached the first screenshot where no other warning happens. I have got a function on a button and this fn defines a global var (anti-pattern) called updatedand when i try to call this value i get an error which is different from calling undefined var.

thheller18:04:19

typing updated in the REPL will look up the updated var in the namespace you are in

thheller18:04:31

it will not look for a "global" var

thheller18:04:42

for that you'd use js/updated

Akiz18:04:02

sure, but then i should get :underclared-var, no?

Akiz18:04:19

i am just trying to understand the error, not fix the problem 🙂

thheller18:04:41

well is the namespace properly defined?

thheller18:04:48

the error is telling you that events didn't exist

Akiz18:04:51

yes, as you can see i define anything else there with no issues

thheller18:04:02

so I suspect that the namespace just didn't exist or wasn't loaded

thheller18:04:38

this is again really hard to give any kind of advice on without having the full context/code

Akiz18:04:10

Yeah, I understand. Unfortunately, I can’t reproduce it now or share the code. It seems to me that the problem starts to appear when I use flow-storm at the same time and the application (running on different address) is so demanding that WS often disconnects from shadow-cljs. Next time I come across this, I’ll upload a loom video, you’ll see that the namespace is usable, but only some variables return that ‘undefined’ error.

thheller19:04:19

this isn't very helpful to me

thheller19:04:29

I do not know what state the REPL is in when the video starts

thheller19:04:56

for example I can force this error simply by doing (in-ns 'some.thing.that.does.not.exist) and then (def a 1)

thheller19:04:11

I do not know if you loaded the ns that you are in properly or not

thheller19:04:22

the error suggests that you did not

Akiz19:04:16

funny, i cant

thheller19:04:38

oops yeah I fixed that 😛

thheller19:04:54

but regardless the effect is the same since CIDER could be the thing switching the namespace

thheller19:04:06

nrepl keeps its own namespace

Akiz19:04:42

Otherwise, the repl was in a state that basically nothing worked - but the hot-reload on ns works and the code in the application works normally too. understand it’s maybe too abstract.

thheller19:04:00

basically all I can say is: Cannot read properties of undefined (reading 'events') means that it is trying to do user_intercace.modules.element_manager.events.a = 1

thheller19:04:12

but it cannot since user_intercace.modules.element_manager.events does not exist

thheller19:04:43

everything after that is pretty much irrelevant

thheller19:04:34

maybe you need a (require 'user-interface.modules.element-manager.events) first

thheller19:04:44

maybe a load-file, maybe just the ns definition

thheller19:04:59

something that ensures the namespace actually exists before trying to def an extra var in it

Akiz19:04:01

So it remembers that I tried to define “a” and then it returns a different error when I call it than when I try to call something I never tried to define? Interesting

thheller19:04:45

make the distinction of a runtime error and a compiler warning

👍 1
thheller19:04:55

runtime error is something the compiler didn't know about

thheller19:04:02

compiler warning is something it obviously did

thheller19:04:35

you appear to be using some flow storm config

Akiz19:04:39

So maybe the flow-storm may have something to do with it…. I’ll try to come up with a reproducible example over the weekend.

thheller19:04:46

flow storm is a fork of clojurescript

thheller19:04:55

I have never tried it so I do not know what this could be

👍 1
thheller20:04:05

maybe it works if you require that first

thheller20:04:16

or maybe just remove it 😛

Akiz20:04:20

I know, I also asked first in Flowstorm 🙂

thheller20:04:23

seems risky to use 😛

😓 1
Akiz20:04:46

?!

smth> (require '[user-interface.modules.element-manager.events])
[]

jpmonettas20:04:11

I'm not sure what is the current issue since there are many different things on the thread. If the issue is that warning, it is weird, in the sense that I'm not able to reproduce and that code shouldn't be required by anything in cljs land. But anyway that is an easy fix, and should also be harmless.

Akiz20:04:30

@U0739PUFQ Sorry, I already updated that message in flow-storm thread.