Skip to content

RTK 2.0 Migration: upsertQueryEntries does not allow refetch behavior #4717

@JacobJaffe

Description

@JacobJaffe

Hi, I've been testing out migrating from upsertQueryData to upsertQueryEntries.

Before:

          await Promise.all(
            posts.map((post) =>
              dispatch(
                postsApi.util.upsertQueryData(
                  "getPost",
                  {
                    id: post._id,
                  },
                  post
                )
              )
            )
          );

After:

          dispatch(
            postsApi.util.upsertQueryEntries(
              posts.map((post) => ({
                endpointName: "getPost",
                arg: {
                  id: post._id,
                },
                value: post,
              }))
            )
          );

However, I've found that the refetching no longer works when initialized this way. I've verified that the tags get invalidated, but no new query gets fired off.

const { refetch } = useGetPost({ id: "foo" });
...

// does not work when the query is hydrated by `upsertQueryEntries`
refetch()

This is unexpected because this is a different behavior than the mapped-upsertQueryData behavior, and feels like a bug- I've connected a component via a useQuery hook, so the subscription should be valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions