-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Race condition on <Can /> #128
Comments
I tried to fork, clone, and test the package before making any changes (and a pull request), but I can't figure out how to get the tests to run. |
Alright, figured out how to get it to run, and submitted a PR #129 |
I see. Thanks for the issue! |
published in |
Thanks for the quick update! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, it might not actually be a race condition, as the intended action loses every time, but:
When the component's
componentWillReceiveProps
is called with a newAbility
instance, asetState
is called, and then the component'sconnectToAbility
is called which ultimately fires offthis.recheck()
.casl/packages/casl-react/src/Can.js
Lines 54 to 61 in 774457a
That method (
this.recheck
) callsthis.check
and usesthis.props
asparams
andthis.state.ability
as the ability. However, the call stack is still nested undercomponentWillReceiveProps
, so the props we're rechecking against are the old props, and the state is most likely not the (now updated) state (see: https://reactjs.org/docs/react-component.html#setstate)!The result is that the render method uses
this.state.allowed
which was (likely) produced erroneously as described above.Therefore a good solution to this problem is to move the call to
connectToAbility
into thesetState
callback:The text was updated successfully, but these errors were encountered: