hyperfiddle/electric

Photon compiler cannot resolve vars only defined in :clj

dustingetz opened this issue · 1 comments

This is pretty annoying. Straightforward to fix we believe:

Photon compiler (which today runs in macroexpansion during clojurescript compilation for historical reasons) can resolve vars differently.

Note that we have to resolve symbols to know if they are macros (which is indicated by meta :macro true on the var), and the p/client compiler does need to understand macros in p/server blocks so that client and server can align.

Looks like this:

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: /Users/dustin/Desktop/photon-datomic-viewer/src/user.cljs:10:18
--------------------------------------------------------------------------------
   7 | (defonce reactor nil)
   8 | 
   9 | (defn ^:dev/after-load start! []
  10 |   (set! reactor ((p/boot
------------------------^-------------------------------------------------------
 Use of undeclared Var user/tx-attrs
--------------------------------------------------------------------------------
  11 |                    (try
  12 |                      (binding [dom/node (dom/by-id "root")]
  13 |                        (p/server
  14 |                          (binding [app.core/conn user/datomic-conn
--------------------------------------------------------------------------------

Root cause is the guarded require:

(ns app.core
  (:require [hyperfiddle.photon :as p]
            [hyperfiddle.photon-dom :as dom]
            [hyperfiddle.photon-ui :as ui]
            #?(:clj [app.queries :refer :all])) ; <<<<<<<<<<<<<<<
  #?(:cljs (:require-macros app.core)))

Runtime error:

ERROR hyperfiddle.photon-jetty-adapter: Websocket handler failure #error {
 :cause Unable to resolve symbol: a-overview
 :data {}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message Unable to resolve symbol: a-overview
   :data {}
   :at [hyperfiddle.photon_impl.runtime$eval$fn__16225 invoke runtime.cljc 1138]}]
 :trace
 [[hyperfiddle.photon_impl.runtime$eval$fn__16225 invoke runtime.cljc 1138]
  [hyperfiddle.photon_impl.runtime$compile$walk__16084 invoke runtime.cljc 821]
  [hyperfiddle.photon_impl.runtime$compile$walk__16084$fn__16092 invoke runtime.cljc 807]

fixed in August