Fork me on GitHub
#figwheel-main
<
2020-07-15
>
niclasnilsson09:07:43

I have an odd thing here. I connect two browsers (localhost) and (figwheel.repl/conns) shows two connections, and changes are seen in both. However, when I connect a third browser, the second connection is gone from the connection list, and only the 1:st and the 3:rd are updated. If I connect a fourth browser/tab, the same thing happens (1:st and n:th are working). If I kill figwheel, all browsers notices and tries to reconnect, and when figwheel is up again, it looks like they succeed:

[Log]  [goog.net.WebSocket] Opening the WebSocket on  (console.js, line 203)
[Log]  [goog.net.WebSocket] WebSocket opened on  (console.js, line 203)
[Log]  [Figwheel REPL] Session ID: 0af956ad-535b-451c-9303-779b586ca4a7 (console.js, line 203)
[Log]  [Figwheel REPL] Session Name: Marvin (console.js, line 203)
but - (figwheel.repl/conns) shows only one, and they are not affected by change. What could I have messed up?

niclasnilsson10:07:36

Ok, I found a pattern. If I restart figwheel, all tabs connect again, but only the new one opened by figwheel (or the one I decide to refresh if I use :open-url false) is seen in the connection list. If I now switch to an existing tab (that thinks it’s reconnected, and the log looks like above), then that becomes the only connection (the opened one is forgotten). Same with all tabs that existed pre killing figwheel. However, any new tab ends up in the connection list as expected and is updated as expected. The pre-existing ones just looks in the console as they reconnected, but if I use any of them, figwheel forgets about the prev focused connection, and instead use the old tab refreshed as the focused one, and forgets about the recently focused one.

niclasnilsson10:07:08

So in essence: Old tabs seems like they reconnect, but they don’t get updates and figwheel don’t know about the connections. If I refresh an old tab, the new tab (created after restart) is not in the list anymore.

niclasnilsson10:07:58

Am I doing something wrong or is it a bug? (Tried with 4 different browsers, same result).

bhauman12:07:54

You aren’t doing something wrong

bhauman12:07:50

@niclasnilsson several things to keep in mind here, figwheel.main repl connections isolate by unique process/build id. The old ones may connect but they don’t get updates or REPL evaluations. Figwheel should send code changes to all connections with the right unique process/build id. However repl eval focus jumps to the focused tab. REPL eval only goes to one client. You can change this behavior with :broadcast and :broadcast-reload options https://figwheel.org/config-options#broadcast-reload

niclasnilsson12:07:13

Ok, so if I restart figwheel, I shall really close all old tabs? (Since reloading them disconnects new tabs), @bhauman

bhauman12:07:36

OR shift reload them?

niclasnilsson12:07:31

Shift-reloading doesn’t seem to help. The pattern is quite odd. Here is what I got:

niclasnilsson12:07:31

;;
;; Starting figwheel
;;

nicke@nicbook% clj -A:dev
2020-07-15 14:34:51.174:INFO::main: Logging initialized @4595ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Compiling build dev to "target/public/cljs-out/dev-main.js"
[Figwheel] Successfully compiled build dev to "target/public/cljs-out/dev-main.js" in 1.731 seconds.
[Figwheel] Watching paths: ("src") to compile build - dev
[Figwheel] Starting Server at 
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
          (figwheel.main/stop-builds id ...)  ;; stops Figwheel autobuilder for ids
          (figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
          (figwheel.main/reset)               ;; stops, cleans, reloads config, and starts autobuilder
          (figwheel.main/build-once id ...)   ;; builds source one time
          (figwheel.main/clean id ...)        ;; deletes compiled cljs target files
          (figwheel.main/status)              ;; displays current state of system
Figwheel REPL Controls:
          (figwheel.repl/conns)               ;; displays the current connections
          (figwheel.repl/focus session-name)  ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
JavaScript environment will not launch automatically when :open-url is false

;;
;; Opening  in a Chrome tab
;;

ClojureScript 1.10.339
cljs.user=> (figwheel.repl/conns)
Will Eval On:  Mable
Session Name     Age URL
Mable             0m /figwheel-connect
nil

;;
;; Opening  in a Firefox tab
;;

cljs.user=> (figwheel.repl/conns)
Will Eval On:  Francisco
Session Name     Age URL
Francisco         0m /figwheel-connect
Mable             1m /figwheel-connect
nil
cljs.user=>

;;
;; Killing and restarting figwheel process
;;

nicke@nicbook% clj -A:dev
2020-07-15 14:36:11.170:INFO::main: Logging initialized @4499ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Compiling build dev to "target/public/cljs-out/dev-main.js"
[Figwheel] Successfully compiled build dev to "target/public/cljs-out/dev-main.js" in 1.753 seconds.
[Figwheel] Watching paths: ("src") to compile build - dev
[Figwheel] Starting Server at 
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
          (figwheel.main/stop-builds id ...)  ;; stops Figwheel autobuilder for ids
          (figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
          (figwheel.main/reset)               ;; stops, cleans, reloads config, and starts autobuilder
          (figwheel.main/build-once id ...)   ;; builds source one time
          (figwheel.main/clean id ...)        ;; deletes compiled cljs target files
          (figwheel.main/status)              ;; displays current state of system
Figwheel REPL Controls:
          (figwheel.repl/conns)               ;; displays the current connections
          (figwheel.repl/focus session-name)  ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
JavaScript environment will not launch automatically when :open-url is false

;;
;; Reloading Chrome tab
;;

ClojureScript 1.10.339
cljs.user=> (figwheel.repl/conns)
Will Eval On:  Mable
Session Name     Age URL
Mable             0m /figwheel-connect
nil

;;
;; Reloading Firefox tab. (Chrome tab gone)
;;

cljs.user=> (figwheel.repl/conns)
Will Eval On:  Lilian
Session Name     Age URL
Lilian            0m /figwheel-connect
nil
cljs.user=>

;;
;; Reloading Chrome tab again. (Firefox tab gone)
;;

cljs.user=> (figwheel.repl/conns)
Will Eval On:  Mable
Session Name     Age URL
Mable             0m /figwheel-connect
nil
cljs.user=>

;;
;; Opening  in Safari
;;

cljs.user=> (figwheel.repl/conns)
Will Eval On:  Vanita
Session Name     Age URL
Vanita            1m /figwheel-connect
Mable             2m /figwheel-connect
nil

;;
;; Reloading Firefox tab (Safari tab gone)
;;

cljs.user=> (figwheel.repl/conns)
Will Eval On:  Lilian
Session Name     Age URL
Lilian            0m /figwheel-connect
Mable             2m /figwheel-connect
nil
cljs.user=>

niclasnilsson12:07:23

and so on. Whichever is refreshed, some other is lost. The tab connection becomes kind “toxic”.

bhauman12:07:44

if you close the old tabs this doesn’t happen though?

niclasnilsson13:07:29

Nope, then it work as I’d expect

bhauman13:07:42

OK cool I’m going to take a look at this.

bhauman13:07:10

@niclasnilsson thanks for reporting this 🙂

niclasnilsson13:07:02

@bhauman, on kind of the same topic, when the old tabs automatically reconnect after a figwheel restart, what’s the reason that they don’t get treated as “full citizens” and gets updates and stuff? Is it tricky or unsafe in some way? ’Cause from a dev point, the most awesome thing would of course be if they just reconnected and participated in the same way as they did before?

bhauman13:07:09

it is tricky, how old is the tab? Was the code compiled with the same version of figwheel/clojurescript? Really confusing things can happen

eval-on-point22:07:39

Is the guide for including NPM modules https://figwheel.org/docs/npm.html meant to be followed for development profiles? When I include :target :bundle, figwheel no longer is able to bring up a cljs repl

eval-on-point22:07:32

deps.edn:
{:paths   ["src"]
 :deps    {org.clojure/clojure       {:mvn/version "1.10.1"}
           org.clojure/clojurescript {:mvn/version "1.10.773"}
           reagent                   {:mvn/version "0.10.0"}}
 :aliases {:dev {:extra-deps  {devcards {:mvn/version "0.2.7"}}
                 :extra-paths ["devcards" "resources" "test"]}
           :fig {:extra-deps
                 {com.bhauman/figwheel-main {:mvn/version "0.2.10"}}
                 :extra-paths ["target"]}}}

eval-on-point22:07:18

dev.cljs.edn:

{:main          {{my-proj}}.cards
 :target        :bundle
 :bundle-cmd    {:none ["npx" "webpack" "--mode=development"
                        :output-to "-o" :final-output-to]}
 :devcards      true
 :optimizations :none
 :pretty-print  true
 :source-map    true}

eval-on-point14:07:34

Figured this out. My custom index.html did not pull in the right js file.