reagent-project / reagent-template

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

browser fails to load fresh figwheel created javascript #19

Closed yatesco closed 9 years ago

yatesco commented 9 years ago

When making a change in a cljs file figwheel compiles it, states notifying browser that file changed: ... but the browser ignores the latest and throws a warning: 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.

Steps to reproduce:

The behaviour is the same regardless of whether the browser-repl is started and attached to the browser.

Tested in latest Chromium and Firefox.

escherize commented 9 years ago

:+1: I'm getting this as well.

Tested in Chrome.

I did notice that this message disappears when I pass in a function instead of a vector.

    (r/render-component [:h2 "doesn't work"] (.getElementById js/document "app"))

    (r/render-component [(fn [] [:h2 "works"])] (.getElementById js/document "app"))
yogthos commented 9 years ago

Turns out the problem is with the code here:

(secretary/defroute "/" []
  (session/put! :current-page home-page))

(secretary/defroute "/about" []
  (session/put! :current-page about-page))

The variable referring to the page ends up being bound in a namespace that's not refreshed, so when changes are pushed the stale variable is still in use. using a function gets around the problem.

In the next release of ClojureScript it'll be possible to do the following to get around the problem:

(secretary/defroute "/" []
  (session/put! :current-page #'home-page))

(secretary/defroute "/about" []
  (session/put! :current-page #'about-page))

Using (fn [] ) as @escherize doing is another way to get around that.

yogthos commented 9 years ago

updated the template to latest ClojureScript and added the fix for reloading.

royki commented 9 years ago

I am getting this now. How to fix it ????

yogthos commented 9 years ago

This should work as long as the top level components that are being reloaded are referenced using #' or wrapped using (fn [] ). I'm not able to reproduce the issue using the latest template.

ftravers commented 9 years ago

Also make sure the file that does your defroute has

^:figwheel-always

in the namespace.