tonsky / rum

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript
Eclipse Public License 1.0
1.8k stars 126 forks source link

daiquiri: fragment? fails on vectors #235

Closed jwr closed 3 years ago

jwr commented 3 years ago

As I'm trying to migrate to rum 0.12, I get lots of errors like this one:

Uncaught Error: Doesn't support name: [object Object]
    at cljs$core$name (core.js:31225)
    at daiquiri$util$fragment_QMARK_ (util.js:73)
    at daiquiri$interpreter$interpret_vec (interpreter.js:155)
    at daiquiri$interpreter$interpret (interpreter.js:172)

From what I can understand, it seems those happen when daiquiri encounters a structure like this example: [:div [[:div] [:div]]], which I thought was legal.

Looking at interpret, it calls fragment? first, which throws an error if it can't use name, and the cond in interpret never has a chance to get to the :else (interpret-seq x) clause.

I think I'm missing something: I'm not sure I understand how this code can work at all, unless nobody generates multiple children of an element. That's why I'm not proposing any code or fixes. (EDIT: I just checked, and fragment? was introduced in rum 0.12.4, which might explain why this hasn't been noticed by more people)

roman01la commented 3 years ago

thanks for reporting this, resolve in 0.12.6

jwr commented 3 years ago

Thanks! (though I don't think 0.12.6 is available on Clojars yet)

Also, thank you for all your work on Rum. Any chance Github sponsors will approve you anytime soon? Has anything changed?

jetmind commented 3 years ago

@roman01la Any hint when 0.12.6 will be available on clojars? Still not there :)

roman01la commented 3 years ago

just pushed

jwr commented 3 years ago

Hmm. After switching to 0.12.6 I still get the same problem, just one function deeper:

ERROR [] - Doesn't support name: [object Object] 
Stacktrace: cljs$core$name@http://localhost:10555/js/out/cljs/core.js:31225:17
daiquiri$util$fragment_tag_QMARK_@http://localhost:10555/js/out/daiquiri/util.js:73:54
daiquiri$util$fragment_QMARK_@http://localhost:10555/js/out/daiquiri/util.js:76:90
daiquiri$interpreter$interpret_vec@http://localhost:10555/js/out/daiquiri/interpreter.js:155:38
daiquiri$interpreter$interpret@http://localhost:10555/js/out/daiquiri/interpreter.js:172:47

I think this is caused by vectors of components, as created by this code:

(rum/defc icon-list < rum/static [atts]
  (when (seq atts)
    [:.icon-list {}
     (mapv (fn [{:attachment/keys [id type content-type] :as att}]
             (rum/with-key (icon-link (attachment/url att) type content-type) id))
           (sort-by :attachment/timestamp > atts))]))

Looking at the interpreter, when it sees a vector, it seems to assume that it can call name on the first element, which will not be true for vectors of components.

jwr commented 3 years ago

I don't think I can reopen this issue, but it should be reopened — the problem still exists.

jwr commented 3 years ago

Just FYI, this is a showstopper bug, which keeps me stuck on 0.12.3.

roman01la commented 3 years ago

@jwr could you please double check this with current master? I'm not able to reproduce the issue

jwr commented 3 years ago

Well, not with the current master, but I re-tested with 0.12.6 (which seems to be identical to the master code-wise). I still see the problem, with the exact same data as in my comment from Apr 7 above.

roman01la commented 3 years ago

@jwr should be fixed now, please try test again from master

jwr commented 3 years ago

I can confirm that this fixes the issue — this might be a good time to release a version including this fix?

roman01la commented 3 years ago

@jwr Released in 0.12.7

jwr commented 3 years ago

Thank you, much appreciated!