     nil
 
     :client/stale
-    (vreset! close-reason-ref "Stale Client! You are not using the latest compilation output!")
+    (do
+      (vreset! stale-client-detected true)
+      (vreset! close-reason-ref "Stale Client! You are not using the latest compilation output!"))
 
     :client/no-worker
     (vreset! close-reason-ref (str "watch for build \"" env/build-id "\" not running"))

  (ws-msg {:type :repl/set-ns-complete :id id :ns ns}))

(def close-reason-ref (volatile! nil))

;; FIXME: core.async-ify this
(defn handle-message [{:keys [type] :as msg} done]

    (pr-str {:input text})
    #js {"content-type" "application/edn; charset=utf-8"}))

;; :init
;; :connecting
;; :connected
(defonce ws-status (volatile! :init))

(declare ws-connect-impl)

(defn ws-connect []
  (when (= (@ws-status :init))
    (ws-connect-impl)))

(defn maybe-reconnect []
  (when (and (not @stale-client-detected)
             (not= @ws-status :init))
    (vreset! ws-status :init)
    (js/setTimeout ws-connect 3000)))

(defn ws-connect-impl []
  (vreset! ws-status :connecting)
  (try
    (let [print-fn
          cljs.core/*print-fn*
