-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 useLazyQuery forceUpdate loop regression. #7715
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PR #7655 changed this code so that the Promise.resolve().then(forceUpdate) branch was not taken when queryDataRef.current was falsy, so forceUpdate() was called immediately instead (the else branch). As #7713 demonstrates, the Promise delay is important to avoid calling forceUpdate() synchronously during the initial render, which can lead to an infinite rendering loop. To preserve the intent of #7655, we now do the queryDataRef.current check inside the Promise callback, since the component could have been unmounted before the callback fired.
In some of our tests, onNewData is called between the first render/mount and the useEffect callback that updates queryDataRef.current, so the logic in onNewData that avoids calling forceUpdate if !queryDataRef.current may prevent legitimate forceUpdate calls, if we check queryDataRef.current before the useEffect callback has fired. By setting queryDataRef.current immediately upon creating the new QueryData object, we eliminate this brief window where the component has rendered but queryDataRef.current has not yet been updated.
jcreighton
approved these changes
Feb 15, 2021
This was referenced Mar 11, 2021
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #7655 changed this code so that the
Promise.resolve().then(forceUpdate)
branch was not taken whenqueryDataRef.current
was falsy, soforceUpdate()
was called immediately instead (theelse
branch).As #7713 demonstrates, the
Promise
delay is important to avoid callingforceUpdate()
synchronously during the initial render, which can lead to an infinite rendering loop.To preserve the intent of #7655, we now do the
queryDataRef.current
check inside thePromise
callback, since the component could have been unmounted before the callback fired.Remaining work:
src/react/components/__tests__/client/Query.test.tsx