figwheel-main

Jérémie Pelletier 2024-03-02T14:42:35.842139Z

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 Pelletier 2024-03-05T19:13:35.740859Z

if anyone's interested, fixed it by running the body of on-repl in a background thread, using an agent and send-off

Jérémie Pelletier 2024-03-02T14:43:23.749709Z

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 Pelletier 2024-03-02T14:44:44.964399Z

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 Pelletier 2024-03-02T14:46:14.942179Z

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 Pelletier 2024-03-02T14:47:47.980349Z

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