lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
631 stars 52 forks source link

Runtime error if a nil map is passed for dynamic props #35

Closed tekacs closed 4 years ago

tekacs commented 4 years ago

It appears that using a value of nil in the spread operator / dynamic props results in a runtime error as an attempt is made to index into the nil map.

A minimal reproduction is:

(let [x nil]
  ($ :div {& x}))

Seemingly, calling ($ :div {& nil}) doesn't trigger the issue.

The exception is thrown on this line:

https://github.com/Lokeh/helix/blob/6fc96e4ac330daeb1cb3e8372a13819f67570661/src/helix/impl/props.cljc#L77

The error appears as so:

image

It would be nice to gracefully handle this case as though an empty map were passed, in line with other behaviour throughout Clojure. For now this can be mitigated by constructing the component using the form:

($ :div {& (or x {})})
lilactown commented 4 years ago

I agree. I’ll get to this this week, PR welcome.