figwheel-main

figwheel-main http://figwheel.org
oly 2020-07-31T07:55:07.217300Z

so the namespace is (ns example.test-server) the folder is test/cljs/example/test_runner.cljs and the files do not appear to be put in the target folder

oly 2020-07-31T08:40:40.218700Z

fixed it in the end just not 100% sure how one thing I am curious about is do the test files filename matter ? as in do they have to match the namespace in the main app with _test appending or should they be picked up regardless ?

plexus 2020-07-31T09:14:15.219800Z

seems when changing a Clojure file it does reload it as documented, but my after-load hook isn't being run. When I change a cljs file it does run. Is there something I can do to have the hook also be triggered when it's a clojure-only change?

plexus 2020-07-31T09:32:36.221Z

reading through the code it seems like this is currently not possible, found a very hacky way around it. Our use case it to have hot reloading of server rendered routes by naively refetching the page and replacing the body

(ns lambdaisland.ui.main
  (:require [kitchen-async.promise :as p]))

(defn fetch-and-replace-body! []
  (p/let [response (js/fetch (str js/location))
          text (.text response)]
    (let [parser (js/DOMParser.)
          doc (.parseFromString parser text "text/html")
          new-body (.querySelector doc "body")]
      (set! (.-innerHTML js/document.body)
            (.-innerHTML new-body)))))

;; Figwheel hooks don't work here because they only fire when ClojureScript
;; namespaces are reloaded, not when only Clojure namespaces change. Instead
;; hook into the function that schedules the conditional execution of the
;; after-load hook so we get called every time.
(defonce monkey-patch-figwheel
  (let [after-reloads js/figwheel.repl.after_reloads]
    (set! js/figwheel.repl.after_reloads
          (fn [f]
            (after-reloads f)
            (fetch-and-replace-body!)))))