Fork me on GitHub
#figwheel-main
<
2024-03-02
>
Jérémie Pelletier14:03:35

Ok so I made a terrible hack to call figwheel from the browser to create a self-hosted REPL, and there's a ~10seconds delay after the first request, feels like a timeout from doing things the wrong way

Jérémie Pelletier14:03:23

Using this from cljs, where form is a string from CodeMirror:

(defn send [form ns]
  (frepl/respond-to-connection {:op "demo/repl" :form form :ns ns}))

Jérémie Pelletier14:03:44

And this monstrosity from clj:

(defn on-repl [{:keys [response]}]
  (when (= "demo/repl" (:op response))
    (binding [cljs.env/*compiler* (-> @figwheel.main.watching/*watcher* :watches
                                      first second :figwheel.main/watch-info :compiler-env)]
      (let [forms (cljs.analyzer.api/forms-seq (StringReader. (:form response)))
            f1    (first forms)
            mod   (when (and (list? f1) (= 'ns (first f1)))
                    (second f1))
            forms (conj (if-not mod forms (next forms)) 'do)
            mod   (or mod (symbol (or (:ns response) "cljs.user")))]
        (cljs.repl/evaluate-form
         (fapi/repl-env "dev")
         (assoc (cljs.analyzer/empty-env) :ns (cljs.analyzer/get-namespace mod))
         "<self repl>"
         forms
         (#'cljs.repl/wrap-fn forms))))))

Jérémie Pelletier14:03:14

It works, surprisingly enough, but client requests are pending as if waiting on a timeout when fired within 10secs of each other

Jérémie Pelletier14:03:47

I think the server expects the flow to go from cider-like client -> server -> browser client, but here it's browser client -> server -> browser client