1

When I try to render any Rum's component right in the REPL it fails with the following error message. What am I doing wrong? Is any workaround exists?

: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$1 (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)

Creating a project from the scratch get the same error:

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$1 (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)
Aleksei Sotnikov
  • 633
  • 4
  • 15

1 Answers1

2

This is a known bug of clojurescript. You can use this as a temporary fix:

(when (exists? js/Symbol)
  (extend-protocol IPrintWithWriter
    js/Symbol
    (-pr-writer [sym writer _]
      (-write writer (str "\"" (.toString sym) "\"")))))
Olim Saidov
  • 2,796
  • 1
  • 25
  • 32
  • Is it possible to use this fix with Rum? I just can not figure out how. Could you give an example if it possible? – Aleksei Sotnikov Jul 25 '18 at 07:35
  • @AlekseiSotnikov This issue has nothing to do with Rum. The problem is in cljs printing subsystem which does not handle javascript (native) symbols gracefully. Just run the above code somewhere in your project: it extends IPrintWithWriter protocol for symbols to correctly print them. – Olim Saidov Jul 25 '18 at 07:41
  • Now is works as follows: (label "foo") => #js{"$$typeof" "Symbol(react.element)", :type #object[class$], :key nil, :ref nil, :props #js{":rum/args" ("foo")}, :_owner nil, :_store #js{}} Which is non-informative. I expect the same behaviour as server side rendering, i.e. (label "foo") => [:div {:class "label"} "foo"] Is it possible on a client side? – Aleksei Sotnikov Jul 26 '18 at 06:29
  • @AlekseiSotnikov You should not expect the same behavior because the implementations of rum components are different for browser and server-side rendering. – Olim Saidov Jul 26 '18 at 14:12