Skip to content

refetch query throws error if query was prefetched via SSR and cache hydrationΒ #1088

@alfrescian

Description

@alfrescian

Describe the bug
I have a simple query with following config

{staleTime: Infinity,
    cacheTime: Infinity,
    enabled: true}

that is prefetched via NextJS app.getInitialProps(). When trying to refetch such a query, e.g. via queryCache.invalidateQueries(...) then the refetch fails & throws an error (afaik because the queryFn is not found/set).

To Reproduce
Here is a sandbox: https://codesandbox.io/s/refetch-failed-for-prefetch-queries-w340e?file=/pages/index.js

Expected behavior
the query is properly refetched.

Screenshots
screenshot

Additional context
react-query 2.23.0
next: 9.5.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions