Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling ShouldComponentUpdate throwing an exception #350

Closed
danielcompton opened this issue Mar 8, 2018 · 2 comments
Closed

Handling ShouldComponentUpdate throwing an exception #350

danielcompton opened this issue Mar 8, 2018 · 2 comments
Labels

Comments

@danielcompton
Copy link
Contributor

danielcompton commented Mar 8, 2018

In

:shouldComponentUpdate
(fn shouldComponentUpdate [nextprops nextstate]
(or util/*always-update*
(this-as c
;; Don't care about nextstate here, we use forceUpdate
;; when only when state has changed anyway.
(let [old-argv ($ c :props.argv)
new-argv ($ nextprops :argv)
noargv (or (nil? old-argv) (nil? new-argv))]
(cond
(nil? f) (or noargv (not= old-argv new-argv))
noargv (.call f c c (get-argv c) (props-argv c nextprops))
:else (.call f c c old-argv new-argv))))))
the not= call on line 170 can throw. A minimal example of this is:

(= {:todos 1} (sorted-map 1 2))

This is being tracked in CLJ-2325. It only shows up when using custom types. I don't think it can occur in equality checks between the standard Clojure data structures. A similar issue will need to be raised in CLJS, once the approach to fix it is decided in CLJS.

In the meantime, I wonder if we should wrap not= calls here with a try/catch, returning false if it throws. I'm not sure what the performance impact of this is though?

An alternative approach is for developers to manually reset the key of the React component to force a component re-render.

@danielcompton danielcompton changed the title ShouldComponentUpdate can throw an exception on not= Handling ShouldComponentUpdate throwing an exception Mar 8, 2018
@Deraen Deraen added the bug label Apr 3, 2018
@Deraen
Copy link
Member

Deraen commented Apr 3, 2018

Related: #344

@Deraen
Copy link
Member

Deraen commented May 4, 2018

#373 merged

@Deraen Deraen closed this as completed May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants