reagent-project / reagent-template

A Leiningen template for projects using Reagent.
MIT License
394 stars 55 forks source link

Changing cljs code produces WebSocket error #37

Closed tuhlmann closed 9 years ago

tuhlmann commented 9 years ago

I created a new project with lein new reagent reagenttmp. Then I do a:

lein repl
(require 'reagenttmp.dev)
(in-ns 'reagenttmp.dev)
(start-figwheel)
(browser-repl)

When I connect to http://localhost:3449 all works fine. I see the example page an the Weasel repl is hooked up.

After changing some code in core.cljs (like :h2 into :h3), the code reloads in the browser, but I also see this error output in the browser console:

Figwheel: trying to open cljs reload socket
utils.js:49 Figwheel: socket connection established
repl.js:135 Opened Websocket REPL connection
utils.js:49 Figwheel: notified of file changes
history.js:237 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
repl.js:135 Opened Websocket REPL connection
repl.js:21 Websocket REPL error :occupied
websocket.js:279 WebSocket connection to 'ws://localhost:9001/' failed: Close received after close
repl.js:178 WebSocket error goog.net.WebSocket.ErrorEvent {type: "error_1", target: goog.net.WebSocket, currentTarget: goog.net.WebSocket, propagationStopped_: false, defaultPrevented: false…}
repl.js:163 Closed Websocket REPL connection
utils.js:49 Figwheel: loaded these files
utils.js:62 ("reagenttmp/core.js" "reagenttmp/dev.js")

Is it ok that dev.js is reloaded? That seems to cause a rewiring of the WebSocket connection. I tried to compare that with a chestnut project. On the chestnut side it would only reload the core.js file. But apart from different library versions I can't seem to find the difference.

Thanks, Torsten.

tuhlmann commented 9 years ago

The problem seems to be with the versions. Bumping a minimal chestnut example to the same versions for figwheel, weasel, piggieback and clojurescript results in the same error message.

tuhlmann commented 9 years ago

The workaround I found is to add ^:figwheel-no-load to dev.cljs

tuhlmann commented 9 years ago

This happens because the new ClosureScript versions recompile dependent namespaces. More info is given here: https://github.com/bhauman/lein-figwheel/issues/92

It would still be a good idea I guess to either add ^:figwheel-no-load to the reagent template or store the Weasel connection in a defonce'd atom, as bensu suggests.

yogthos commented 9 years ago

Right, definitely sounds like dev should use ^:figwheel-no-load here.

yogthos commented 9 years ago

I just pushed out a new version with the fix.

tuhlmann commented 9 years ago

Thanks. I created a new project from it. It's working nicely.