Skip to content

Weird results when keepPreviousData is used with transitions #3572

@faradaytrs

Description

@faradaytrs

Describe the bug

Sandbox link

When I click decrease (in the second part of the example), I get unexpected results on example 2.2;
Because other suspense boundaries depend on the same state, useQuery waits for them to render and only starts fetching after transition is complete.
Can somebody explain why we get this result?

If i remove other two Suspense boundaries, everything seems normal.
With keepPreviousData on, it starts fetching only when transition is complete, not sure if it's bug

One more strange thing I noticed is fetching triggered by refetchOnWindowFocus doesn't cause fallback in suspense? Is it right behavior?

Your minimal, reproducible example

https://codesandbox.io/s/funny-leftpad-wf7kbz?file=/src/App.js

Steps to reproduce

Click decrease:
See that full update requires 10 seconds instead of 5.

Expected behaviour

  1. I expected 2.2 to work similarly with 2.1 in sandbox
  2. I expect refetchOnWindowFocus trigger fallback when used with suspense: true and current behaviour can be opt in using useDeferredValue or keepPreviousValue

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Mac OS Monterey
Latest Edge

react-query version

4.0.0-beta.7

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsuspensev4wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions