figwheel-main

figwheel-main http://figwheel.org
niclasnilsson 2020-07-15T09:15:43.040400Z

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 <ws://localhost:9500/figwheel-connect?fwprocess=d9e73b&amp;fwbuild=dev&amp;fwsid=0af956ad-535b-451c-9303-779b586ca4a7&amp;fwsname=Marvin> (console.js, line 203)
[Log]  [goog.net.WebSocket] WebSocket opened on <ws://localhost:9500/figwheel-connect?fwprocess=d9e73b&amp;fwbuild=dev&amp;fwsid=0af956ad-535b-451c-9303-779b586ca4a7&amp;fwsname=Marvin> (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?

niclasnilsson 2020-07-15T10:15:36.046700Z

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.

niclasnilsson 2020-07-15T10:17:08.048200Z

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.

niclasnilsson 2020-07-15T10:17:58.048900Z

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

bhauman 2020-07-15T12:12:54.051700Z

You aren’t doing something wrong

bhauman 2020-07-15T12:19:50.057Z

@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

niclasnilsson 2020-07-15T12:24:13.058500Z

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

bhauman 2020-07-15T12:45:36.059300Z

OR shift reload them?

niclasnilsson 2020-07-15T12:49:31.060300Z

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

niclasnilsson 2020-07-15T12:49:31.060400Z

;;
;; 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 <http://localhost:9500>
[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 <http://localhost:9500> in a Chrome tab
;;

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

;;
;; Opening <http://localhost:9500> in a Firefox tab
;;

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

;;
;; 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 <http://localhost:9500>
[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=&gt; (figwheel.repl/conns)
Will Eval On:  Mable
Session Name     Age URL
Mable             0m /figwheel-connect
nil

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

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

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

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

;;
;; Opening <http://localhost:9500> in Safari
;;

cljs.user=&gt; (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=&gt; (figwheel.repl/conns)
Will Eval On:  Lilian
Session Name     Age URL
Lilian            0m /figwheel-connect
Mable             2m /figwheel-connect
nil
cljs.user=&gt;

niclasnilsson 2020-07-15T12:49:31.060500Z

niclasnilsson 2020-07-15T12:51:23.061500Z

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

bhauman 2020-07-15T12:58:44.062700Z

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

niclasnilsson 2020-07-15T13:02:29.063400Z

Nope, then it work as I’d expect

bhauman 2020-07-15T13:09:42.063600Z

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

bhauman 2020-07-15T13:10:10.064Z

@niclasnilsson thanks for reporting this 🙂

niclasnilsson 2020-07-15T13:16:02.067500Z

@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?

bhauman 2020-07-15T13:26:09.068900Z

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

niclasnilsson 2020-07-15T13:32:49.069600Z

Ok, got it.

Mitch 2020-07-15T22:50:39.072600Z

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

Mitch 2020-07-16T14:41:34.078400Z

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

Mitch 2020-07-15T22:52:32.072800Z

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"]}}}

Mitch 2020-07-15T22:54:18.073200Z

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}