-
Notifications
You must be signed in to change notification settings - Fork 13.1k
[FIX] Fix infinite loop in federation dashboard #19386
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
[FIX] Fix infinite loop in federation dashboard #19386
Conversation
b72d1fa to
79eaa70
Compare
The infinite loop was caused by the improper comparison of a useEffect dependency. useEffect uses Object.is(previous, current) do determine if it should rerun the effect or not. Since we're using args, which in the federation calls is an empty array literal, it will always return false. Initially this was passed as ...args, which didn't cause any problems. It was changed in RocketChat#18438, an unrelated Omnichannel admin dashboard rewrite that also uses useMethodData. Changing it to JSON.stringify(args) ensures that we're comparing strings instead of arbitrary objects, solving the problem. This pattern seems to be used in other useEffects as well throughout the codebase.
|
Ugh, I fixed this in 3.6.3, but it seems that I'm not sure if using I'll rebase this again and remove Thoughts? |
79eaa70 to
47b5a08
Compare
tassoevan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, eslint-plugin-react-hooks is ineffective when the dependency array of a hook has complex expressions: it expects only variable references.
A better workaround might be using this custom hook to memoize args internallly.
|
Thanks for the review.
Hm, I see the advantages of not having a complex expression in the dependency list.
Using
This may be me walking in circles. Maybe it would make more sense to build What do you think? Is thinking of complex args worth it? Is there a simpler solution? |
|
@tassoevan do you have any thoughts on my last comment? Should I close this PR? maybe it has been fixed in the meantime. |
Proposed changes
The infinite loop was caused by the improper comparison of a useEffect
dependency.
useEffect uses Object.is(previous, current) do determine if it should
rerun the effect or not. Since we're using args, which in the federation
calls is an empty array literal, it will always return false.
Initially this was passed as ...args, which didn't cause any problems.
It was changed in #18438 (in a sub-pull request, in this commit 05ca878), an unrelated Omnichannel admin dashboard
rewrite that also uses useMethodData.
Changing it to JSON.stringify(args) ensures that we're comparing strings
instead of arbitrary objects, solving the problem. This pattern seems to
be used in other useEffects as well throughout the codebase.
Issue(s)
#19007
Types of changes
Checklist
Changelog