From 62f87292a2ed8622da51a38bf1f60d86e11374ee Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Wed, 14 Nov 2018 22:31:50 +0200 Subject: [PATCH] Fix #401 if jsprops is nil before adding key, key is lost If jsprops was nil before key oset call, oset created a new object for the jsprops, but because the return value from oset was not used, the object was lost. --- src/reagent/impl/template.cljs | 5 +++-- test/reagenttest/testreagent.cljs | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 7dfa83f..e9fc660 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -323,9 +323,10 @@ (let [props (nth argv 1 nil) hasprops (or (nil? props) (map? props)) jsprops (convert-prop-value (if hasprops props)) + jsprops (if-some [key (key-from-vec argv)] + (oset jsprops "key" key) + jsprops) first-child (+ 1 (if hasprops 1 0))] - (when-some [key (key-from-vec argv)] - (oset jsprops "key" key)) (make-element argv react/Fragment jsprops first-child))) (defn adapt-react-class diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 7c74e19..b870543 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -1189,8 +1189,12 @@ [:div "hello"] [:div "world"]] ^{:key 2} - [children])])] - (is (= "
hello
world
foo
" + [children] + ^{:key 3} + [:<> + [:div "1"] + [:div "2"]])])] + (is (= "
hello
world
foo
1
2
" (as-string [comp])))))) (defonce my-context (react/createContext "default"))