Skip to content

Unnecessary rendering on data re-fetching #938

Closed

Description

@martinbavio

Describe the bug
I was using why-did-you-render in local and noticed a bunch of unnecessary re-renders happening because of something related to react-query that goes beyond my power as a lib consumer.

To Reproduce

  1. Go to https://next-auth-1b8mmpq6w.vercel.app/
  2. Check console.
  3. Switch tab back and forth to regain window focus.
  4. Check console again to see unnecessary re-renders happening.

Expected behavior
It should not re-render if data is the same.

Additional context

Activity

  1. changed the title [-]Unnecessary re-renders[/-] [+]Unnecessary rendering on data refetching[/+] on Aug 28, 2020
  2. changed the title [-]Unnecessary rendering on data refetching[/-] [+]Unnecessary rendering on data re-fetching[/+] on Aug 28, 2020
  3. tannerlinsley commented on Aug 28, 2020

    @tannerlinsley
    Member

    This seems relatively new. @boschni, @Ephem any ideas here?

  4. vincentjames501 commented on Aug 28, 2020

    @vincentjames501

    I just ran into the same thing on a React Native app that is causing our iOS refresh control to "flicker" when we call refetch. I think the bug may have been introduced in 2.7.x as upgrading from 2.6.0->2.7.0 the issue appears and before 2.7.0 the issue wasn't present.

  5. boschni commented on Aug 29, 2020

    @boschni
    Contributor

    I’m not able to test this specific issue right now, but when refetching, the isFetching and updatedAt properties change. This will trigger at least two renders. I created a flag in #840 which will allow you to prevent these additional renders.

  6. ankursehdev commented on Aug 30, 2020

    @ankursehdev

    I am facing a similar issue too, I have few components on a page - Select Dropdown being one. If I click that dropdown the query is trying to fetch the data again. I don't know why.

    Even on this demo, if you click somewhere post request is firing, is it the right behaviors? Check the GIF below.

    I wonder, is it because I am losing focus on the tab and regaining it once I click back? I am new to react-query actually.

    react-query-thing

  7. boschni commented on Aug 31, 2020

    @boschni
    Contributor

    Hi @ankursehdev! Yes in both cases the additional renders are because the query is being revalidated on window focus. You can either disable this behaviour with refetchOnWindowFocus or wait for #840 to be merged which will allow you to keep the revalidation, but prevent additional renders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions