cjohansen / replicant

A native ClojureScript virtual DOM renderer - render hiccup directly
223 stars 10 forks source link

Life-cycle hooks broken? #18

Closed larstvei closed 9 months ago

larstvei commented 9 months ago

Hi!

I have not been able to use the life-cycle hooks, so I think they are broken in the current version.

The bug can be reproduced by the example in the README:

(require '[replicant.dom :as replicant])

(replicant/set-dispatch!
  (fn [replicant-data hook-data]
    (prn "DOM changed")))

(replicant/render
  (js/document.getElementById "app")
  [:h1 {:replicant/on-update ["Update data"]} "Hi!"])

I get an error like this in the browser:

core.cljc:292 Uncaught TypeError: Cannot read properties of null (reading '7')
    at Function.cljs$core$IFn$_invoke$arity$variadic (core.cljc:292:68)
    at replicant$core$register_hook (core.cljc:285:1)
    at replicant$core$create_node (core.cljc:418:8)
    at core.cljc:457:37
    at core.cljs:1528:24
    at Function.cljs$core$IFn$_invoke$arity$4 (core.cljs:1528:23)
    at Object.cljs$core$IReduce$_reduce$arity$3 (core.cljs:1664:6)
    at Function.cljs$core$IFn$_invoke$arity$3 (core.cljs:2570:17)
    at cljs$core$reduce (core.cljs:2538:1)
    at replicant$core$insert_children (core.cljc:456:9)
cjohansen commented 9 months ago

Oops! This failed specifically for first render in ClojureScript only 😅 I've primarily focused on the Clojure tests - there are some differences because the cljs version uses native arrays (which don't have nil punning), see the commit message if interested. Thanks for reporting!