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

Fix useLazyQuery forceUpdate loop regression. #7715

Merged
merged 3 commits into from
Feb 15, 2021
Merged

Commits on Feb 15, 2021

  1. Fix useLazyQuery forceUpdate loop regression.

    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.
    benjamn committed Feb 15, 2021
    Configuration menu
    Copy the full SHA
    d3735a9 View commit details
    Browse the repository at this point in the history
  2. Set queryDataRef.current immediately to avoid race.

    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.
    benjamn committed Feb 15, 2021
    Configuration menu
    Copy the full SHA
    6bfa64b View commit details
    Browse the repository at this point in the history
  3. Mention PR #7715 in CHANGELOG.md.

    benjamn committed Feb 15, 2021
    Configuration menu
    Copy the full SHA
    0b2dee0 View commit details
    Browse the repository at this point in the history