Fix useLazyQuery forceUpdate loop regression. #7715
Merged
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