Fork me on GitHub
#shadow-cljs
<
2020-08-15
>
kenny17:08:46

I’m using chromex with shadow-cljs. When I connect to the REPL using (shadow/nrepl-select :extension) , I appear to be connected to the browser environment within the extension. Anyone familiar with chromex to know how to get the REPL connected to the browser environment for the content-script (i.e., the actual loaded browser page)?

kenny17:08:40

Given this output,

(shadow/repl-runtimes :extension)
=>
[{:since #inst"2020-08-15T17:10:59.182-00:00",
  :proc-id "7453f221-866f-4e45-ae1a-49c489d30616",
  :connection-info {:remote true, :websocket true},
  :client-id 47,
  :user-agent "Chrome 537.36 [MacIntel]",
  :type :runtime,
  :lang :cljs,
  :build-id :extension,
  :host :browser,
  :dom true}
 {:since #inst"2020-08-15T17:11:01.035-00:00",
  :proc-id "7453f221-866f-4e45-ae1a-49c489d30616",
  :connection-info {:remote true, :websocket true},
  :client-id 48,
  :user-agent "Chrome 537.36 [MacIntel]",
  :type :runtime,
  :lang :cljs,
  :build-id :extension,
  :host :browser,
  :dom true}]
is the runtime-id the same as the client-id?

kenny17:08:08

I see this fn shadow/repl-runtime-select. Calling it with the client-id of 48 (seen above) and then running (shadow/nrepl-select :extension) does not result in the REPL calls getting eval’ed in the client-script environment.

kenny18:08:55

Perhaps there’s a way to pass in a function for how to select the default runtime id?

kenny18:08:56

This seems like it’d work. Must be missing something.

(shadow/repl-runtime-select :extension 88)
=> true
(:default-runtime-id @(:state-ref (shadow/get-worker :extension)))
=> 87

thheller18:08:16

@kenny this isn't currently supported. I broke it in the 2.10 REPL updates. https://github.com/thheller/shadow-cljs/issues/776

kenny18:08:23

Ah, okay. Perhaps easiest to go back to 2.9.10 then?

thheller18:08:10

honestly not sure how reliable it previously was. not aware of anyone ever actually using it.

kenny18:08:02

Ah. Perhaps folks using chromex don’t also use shadow-cljs.

thheller18:08:51

doesn't have anything to do with chromex. the problem also exists when I work on the shadow-cljs UI which uses a webworker and so always has two runtimes and its kinda annoying to switch.

kenny18:08:46

Chromex also necessitates 2 runtimes. Without support for runtime switching, you can only interact with 1 runtime. It seems incredibly painful to work without a repl!

kenny18:08:37

Thus the conclusion previously drawn. If you’re also in the same situation, how do you switch between the different runtimes?

thheller18:08:24

I don't currently. I only use the REPL via Inspect when looking at some data stuff. Otherwise just relying on hot-reload.

kenny18:08:24

Life without access to a repl seems dark 🙂

thheller18:08:03

I barely ever use the REPL in CLJS for some reason. I use it for everything in CLJ but somehow hot-reload works better for me in CLJS

kenny18:08:37

I do that often when working on our prod app at work. I’m currently messing with an old cljs code base and just wanted to explore what stuff did, immediately reaching for the repl.

kenny18:08:56

Anyway, 2.9.10 with (shadow/nrepl-select :extension {:runtime-id "<id>"}) does work. One thing that is frustrating with explicitly specifying the runtime id is if you refresh your browser, the id changes.

cfleming23:08:31

@thheller I’m looking at @pavel.klavik’s problem with UTF in Cursive. Am I correct in thinking that that exception is when the Shadow server is reading a transit response, presumably the response from the CLJS client?

cfleming23:08:55

I’m not super familiar with how Shadow works, so I’m not sure where transit would be being used. My mental model of how this eval would be passed is:

Cursive nREPL client -> Shadow nREPL server -> CLJS client
But I thought that second step was usually passed as a string rather than transit/JSON.

cfleming23:08:58

@pavel.klavik Do you have your IntelliJ configured to use UTF-8 under Settings-&gt;Editor-&gt;General-&gt;Console?

Pavel Klavík23:08:27

I have this there:

Pavel Klavík23:08:37

Changing to UTF-8 does not seem to help.

cfleming23:08:34

It looks like your system encoding is not set to UTF-8, which might cause this problem. I’m trying to figure out how to set that, one sec…

cfleming23:08:01

Ok, if you go to Help | Edit Custom VM Options and add -Dfile.encoding=UTF-8 there, then restart IntelliJ, does that help?

cfleming23:08:28

In the same config pane you posted above, you should then see: System Default: UTF-8

Pavel Klavík23:08:04

It shows now UTF-8 as System Default, but the error stays the same

cfleming23:08:20

Hmm, I’m running out of ideas then, I’m afraid.

cfleming23:08:36

I have to go now, but I’ll think about it and look into it more next week.

Pavel Klavík23:08:08

Sure, thx a lot 🙂.

cfleming23:08:06

Also, when you eval this do you see anything in your Network pane of developer tools?

Pavel Klavík23:08:22

You mean in Chrome? Not sure how to display anything there from Shadow-cljs