Fork me on GitHub
#shadow-cljs
<
2020-12-27
>
Neros03:12:30

Hey people, hope Christmas went well.  I am trying to get React QR Scanner to work in shadow-cljs and am having problems getting it working. I converted the following react code:

[12:02 AM] import React, { Component } from 'react'
import QrReader from 'react-qr-scanner'

class Example extends Component {
  constructor(props){
    super(props)
    this.state = {
      delay: 500,
      result: 'No result',
    }

    this.handleScan = this.handleScan.bind(this)
  }
  handleScan(result){
    if(result){
      this.setState({ result })
    }
  }
  handleError(err){
    console.error(err)
  }
  render(){
    const previewStyle = {
      height: 240,
      width: 320,
    }

    return(
      <div>
        <QrReader
          delay={this.state.delay}
          style={previewStyle}
          onError={this.handleError}
          onScan={this.handleScan}
          />
        <p>{this.state.result}</p>
      </div>
    )
  }
}
[12:04 AM] I converted it from class to functional in react then converted it to cljs: (defn example   []   (let [state (r/atom {})         preview-style {:height "240" :width "320"}]     [:<>      (fn []        [:div         [:> QrReader {:name "qr-reader"                       :delay (:qr-reader @state)                       :style preview-style                       :on-error (fn [e]                                   (prn "You have an Error Bitch!"))                       :on-scan (fn [e]                                  (swap! state assoc :qr-reader                                         (-> e .-target .-value)))}]])])) I had made a few variations of the above and keep running into issues, any suggestions would be most welcome. Thankyou.

Christopher Genovese03:12:27

I'm having a repl problem I've never had before immediately after the first hot reload, when running a shadow-cljs server and connecting to it via a repl. The repl loses track of all namespaces and eventually hangs. Specifically:

Christopher Genovese03:12:53

cljs.user> (require '[app.ui :as ui] '[app.client :as client] '[com.fulcrologic.fulcro.application :as app]) nil cljs.user> (app/current-state client/app) {...stuff here looks good...} ;; ...examine a few more gits of data cljs.user> (app/current-state client/app) {...stuff here still looks good...} ;; Then after the first hot reload in shadow-cljs following a minor change in a file cljs.user> (app/current-state client/app) ------ WARNING - :undeclared-ns ------------------------------------------------ Resource: <eval>:1:2 No such namespace: app, could not locate app.cljs, app.cljc, or JavaScript source providing "app" -------------------------------------------------------------------------------- ------ WARNING - :undeclared-var ----------------------------------------------- Resource: <eval>:1:2 Use of undeclared Var app/current-state -------------------------------------------------------------------------------- ------ WARNING - :undeclared-ns ------------------------------------------------ Resource: <eval>:1:20 No such namespace: client, could not locate client.cljs, client.cljc, or JavaScript source providing "client" -------------------------------------------------------------------------------- ------ WARNING - :undeclared-var ----------------------------------------------- Resource: <eval>:1:20 Use of undeclared Var client/app -------------------------------------------------------------------------------- ;; After this simple arithmetic expressions work for a bit, but eventually -- and ;; immediately after requiring anything, the repl times out and then hangs. ;; For instance, re-doing the above require gives this error [2020-12-26 22:35:10.636 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:op :cljs-compile, :input {:code "(require\n '[com.kymetis.rav.app.ui :as ui]\n '[com.kymetis.rav.app.client :as client]\n '[com.fulcrologic.fulcro.application :as app])", :ns cljs.user, :repl true}, :include-init false, :call-id 9, :from 5}} AssertionError Assert failed: (symbol? repl-ns) shadow.build.resolve/resolve-repl (resolve.clj:639) shadow.build.resolve/resolve-repl (resolve.clj:639) shadow.cljs.repl/repl-require (repl.clj:211) shadow.cljs.repl/repl-require (repl.clj:187) shadow.cljs.repl/process-read-result (repl.clj:518) shadow.cljs.repl/process-read-result (repl.clj:498) shadow.cljs.repl/process-input (repl.clj:682) shadow.cljs.repl/process-input (repl.clj:660) shadow.cljs.devtools.server.worker.impl/eval17014/fn--17017 (impl.clj:755) clojure.lang.MultiFn.invoke (MultiFn.java:234) shadow.cljs.devtools.server.util/server-thread/fn--16643/fn--16644/fn--16652 (util.clj:285) shadow.cljs.devtools.server.util/server-thread/fn--16643/fn--16644 (util.clj:284) ;; A timeout message is given and then no more response

Christopher Genovese03:12:27

I ran shadow-cljs server and then connected with a cljs-repl.  Using the latest version of shadow-cljs and using the following config: {:deps     {:aliases [:dev]}
 :dev-http {8000 "classpath:public"}
 :builds   {:main {:target     :browser
                   :output-dir "resources/public/js/main"
                   :asset-path "/js/main"
                   :modules    {:main {:init-fn app.client/init
                                       :entries [com.kymetis.rav.app.client]}}
                   :devtools   {:after-load app.client/refresh
                                :preloads   [com.fulcrologic.fulcro.inspect.preload
                                             com.fulcrologic.fulcro.inspect.dom-picker-preload]}}}
 :nrepl {:port 8777}

 :open-file-command ["emacsclient" "-n" ["+%s:%s" :line :column] :file]}

Christopher Genovese03:12:33

When first connecting the browser, it says the JS is stale; a reload fixes it. This is baffling me, and any help would be much appreciated. Thanks.

thheller08:12:24

@genovese sounds like https://github.com/thheller/shadow-cljs/issues/788. unfortunately I haven't been able to reproduce this

Christopher Genovese14:12:33

Thanks, @U05224H0W. You're right, that is an exact match. (Sorry I missed that.) I'll try to document things as clearly as possible on github and produce a minimal example. Any general pointers on where I should look in the shadow-cljs code to track this? This is killing repl-driven development for my project, so I'm motivated. Thanks again

thheller15:12:52

the issue is that somehow it gets the repl into a corrupted state where something that should never be nil is nil

thheller15:12:46

but I somehow can't get into that state. granted I don't use the cljs REPL all that much because of hot-reload

thheller15:12:40

steps to reproduce would help a lot. I'll then happily track it down 🙂

Christopher Genovese16:12:12

Thanks! I'll put my details on github shortly.

Christopher Genovese17:12:17

P.S. @U05224H0W As a shortcut, I tried to redefine shadow.cljs.repl/repl-require to log new-ns-info from within shadow's clj repl before starting the watch, but that didn't work. If you think it worthwhile and let me know the best way to build a branch for debugging, I can help get some info as well since it's happening here.

thheller17:12:47

need to redef this too if you redef the fn

thheller17:12:58

then it should work fine

Christopher Genovese20:12:41

Outstanding, thanks

victorb16:12:42

can I somehow get shadow-cljs to output the server-token (in order to connect to api/remote-relay myself manually) to stdout when running shadow-cljs server ?

victorb16:12:08

the file .shadow-cljs/server.token has the token I need

thheller16:12:10

yeah the file is meant for exactly that 🙂

thheller16:12:19

curious what you intend to build? I still need to document all of this better 😛

victorb16:12:14

eh, just mucking around, wanted to control the build process directly from browser app, via nested babashka (so browser -> ws -> babashka -> babashka -> shadowcljs), got better access with nrepl in the end, after discovering the files from .shadow-cljs/

Mr. Savy17:12:11

I'm having trouble with my repl. If I start it up it starts in the shadow.user namespace. However, after typing in the (shadow/repl :main) command to switch to a cljs repl, my namespace becomes nil and loading/switiching to other namespaces doesn't seem to work; they also return nil. does anyone recognize what I might be doing wrong? I haven't had this problem before, and I don't recall making any changes that may have caused this.

thheller20:12:14

@ajsnow2012 what returns nil? You a switching with shadow/repl that turns the CLJ REPL into CLJS so you should start out at cljs.ujser?

Mr. Savy20:12:55

*ns* return nil when I make the switch. Although, it does seem to think i'm in cljs.user . so here's what i'm seeing directly :

thheller00:12:06

*ns* is not a thing in CLJS. you can see the ns in the bottom right corner

thheller00:12:17

or a quick trick is ::foo or so

Mr. Savy00:12:14

I saw the bottom right, but I thought *ns* worked in both versions. I must be losing my mind. Sorry for the trouble and thank you!

thheller00:12:35

it works in macros but not in the REPL

👍 1