shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Neros 2020-12-27T03:16:30.147700Z

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 Genovese 2020-12-27T03:39:27.149500Z

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 Genovese 2020-12-27T03:39:53.149700Z

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 Genovese 2020-12-27T03:42:27.151200Z

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 Genovese 2020-12-27T03:43:33.152100Z

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.

thheller 2020-12-27T08:07:24.153800Z

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

Christopher Genovese 2020-12-27T14:49:33.154100Z

Thanks, @thheller. 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

thheller 2020-12-27T15:38:52.154300Z

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

thheller 2020-12-27T15:39:46.154800Z

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

thheller 2020-12-27T15:40:40.155Z

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

victorb 2020-12-27T16:08:42.157Z

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 ?

victorb 2020-12-27T16:12:08.157100Z

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

thheller 2020-12-27T16:40:10.157300Z

yeah the file is meant for exactly that 🙂

thheller 2020-12-27T16:42:19.157500Z

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

victorb 2020-12-27T16:45:14.157700Z

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/

Christopher Genovese 2020-12-27T16:57:12.157900Z

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

Christopher Genovese 2020-12-27T17:37:17.158100Z

P.S. @thheller 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.

thheller 2020-12-27T17:39:47.158300Z

need to redef this too if you redef the fn

thheller 2020-12-27T17:39:58.158800Z

then it should work fine

Mr. Savy 2020-12-27T17:51:11.162100Z

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.

thheller 2020-12-27T20:05:14.163300Z

@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. Savy 2020-12-27T20:20:55.163400Z

*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 :

Christopher Genovese 2020-12-27T20:45:41.163900Z

Outstanding, thanks