REPL 中的 Rum 组件渲染因 TypeError 而失败

A Rum's component rendering in the REPL fails by TypeError

当我尝试在 REPL 中渲染任何 Rum 的组件时,它失败并显示以下错误消息。我究竟做错了什么?是否存在解决方法?

:dependencies [[org.clojure/clojure       "1.9.0"]
               [org.clojure/clojurescript "1.10.238"]
               [rum                       "0.11.2"]]
...

=> (rum/defc label [text]
      [:div {:class "label"} text])

=> (label "foo")

 #object[TypeError TypeError: Cannot convert a Symbol value to a string]
   Function.cljs.core.str.cljs$core$IFn$_invoke$arity (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:2944:22)
   cljs.core/pr-writer-impl (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:9994:53)
   cljs$core$pr_writer (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10003:6)
   cljs.core/pr-sequential-writer (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:9857:16)
   cljs.core/print-prefix-map (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10121:4)
   cljs.core/print-map (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10135:8)
   cljs.core/pr-writer-impl (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:9939:12)
   cljs$core$pr_writer (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10003:6)

从头开始创建项目得到同样的错误:

bash-3.2$ lein new figwheel hello-world -- --rum

bash-3.2$ cd hello-world/
bash-3.2$ lein figwheel
...
ClojureScript 1.10.238

dev:cljs.user=> (require '[rum.core :as rum])

dev:cljs.user=> (rum/defc label [text]
           #_=>   [:div {:class "label"} text])
#'cljs.user/label
dev:cljs.user=> (label "foo")
#object[TypeError TypeError: Cannot convert a Symbol value to a string]
   Function.cljs.core.str.cljs$core$IFn$_invoke$arity (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:2944:22)
   cljs.core/pr-writer-impl (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:9994:53)
   cljs$core$pr_writer (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10003:6)
   cljs.core/pr-sequential-writer (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:9857:16)
   cljs.core/print-prefix-map (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10121:4)
   cljs.core/print-map (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10135:8)
   cljs.core/pr-writer-impl (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:9939:12)
   cljs$core$pr_writer (jar:file:/Users/asotnikov/.m2/repository/org/clojure/clojurescript/1.10.238/clojurescript-1.10.238.jar!/cljs/core.cljs:10003:6)

这是一个已知的 bug clojurescript。您可以将其用作临时修复:

(when (exists? js/Symbol)
  (extend-protocol IPrintWithWriter
    js/Symbol
    (-pr-writer [sym writer _]
      (-write writer (str "\"" (.toString sym) "\"")))))