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

equalityF is not a function #1704

Closed
gshilin opened this issue Mar 30, 2021 · 8 comments
Closed

equalityF is not a function #1704

gshilin opened this issue Mar 30, 2021 · 8 comments

Comments

@gshilin
Copy link
Contributor

gshilin commented Mar 30, 2021

After release 7.2.3 I got error "equalityFn is not a function" in a component that beforehand worked perfect. In debugger I see that in useSelector.js in function checkForUpdates value of equalityFn is Array with one element "null":
equalityFn: Array(1)
0: null

I don't know how to reproduce it in a short example.

React: 17.0.2
ReactDOM: 17.0.2
Redux: 4.0.5
React Redux: 7.2.3

@markerikson
Copy link
Contributor

Hmm. The code passes tests and looks valid when I glance at it again. It's going to be hard to investigate this without a reproduction example.

@gshilin
Copy link
Contributor Author

gshilin commented Mar 30, 2021

Found it: for some reason I supplied an array as an equalityFn, probably that was an attempt for some optimization. And it didn't crash in 7.2.2.

@gshilin
Copy link
Contributor Author

gshilin commented Mar 30, 2021

Its call was inside of try-catch:

try {
        var newSelectedState = latestSelector.current(store.getState());

        if (equalityFn(newSelectedState, latestSelectedState.current)) {
          return;

@markerikson
Copy link
Contributor

markerikson commented Mar 30, 2021

I suppose we could add a couple dev-only checks to useSelector to verify that both selector and equalityFn are functions :)

I think what might have been happening before is that it threw an error in the store subscription, but we swallow that error and always queue up a re-render for this component. Then, we re-ran the selector while rendering, it returns a result fine, no equality check, and rendering continues as usual.

Now, same thing happens, but the equality check happens while rendering and explodes again.

@gshilin
Copy link
Contributor Author

gshilin commented Mar 30, 2021

It would be nice to raise an exception when a useSelector is created with wrong properties. At least it would be easy to find it.

@gshilin
Copy link
Contributor Author

gshilin commented Mar 30, 2021

This is the comment from prev version:

// we ignore all errors here, since when the component
// is re-rendered, the selectors are called again, and
// will throw again, if neither props nor store state
// changed

@markerikson
Copy link
Contributor

Yep, agreed. If you've got some time, could you try filing a PR that would throw an error if either selector or equalityFn are not actually functions, in dev mode only?

@gshilin
Copy link
Contributor Author

gshilin commented Mar 30, 2021

Yep, will try tomorrow

gshilin added a commit to gshilin/react-redux that referenced this issue Mar 31, 2021
@gshilin gshilin closed this as completed Mar 31, 2021
charmingdev222 pushed a commit to charmingdev222/react-redux-demo that referenced this issue May 16, 2023
peace19920726 added a commit to peace19920726/React-Redux-Dev that referenced this issue Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants