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.
This commit is contained in:
Juho Teperi 2018-11-14 22:31:50 +02:00
parent d9057eaecf
commit 62f87292a2
2 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -1189,8 +1189,12 @@
[:div "hello"]
[:div "world"]]
^{:key 2}
[children])])]
(is (= "<div><div>hello</div><div>world</div><div>foo</div></div>"
[children]
^{:key 3}
[:<>
[:div "1"]
[:div "2"]])])]
(is (= "<div><div>hello</div><div>world</div><div>foo</div><div>1</div><div>2</div></div>"
(as-string [comp]))))))
(defonce my-context (react/createContext "default"))