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

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

Open
JacobJaffe opened this issue Nov 18, 2024 · 2 comments
Open

Comments

@JacobJaffe
Copy link

JacobJaffe commented Nov 18, 2024

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.

@JacobJaffe JacobJaffe changed the title upsertQueryEntries does not allow refetch behavior RTK 2.0 Migration: upsertQueryEntries does not allow refetch behavior Nov 18, 2024
@markerikson
Copy link
Collaborator

Yep, there was a similar report over in #4393 . Haven't had time to look into it yet.

@JacobJaffe
Copy link
Author

I think you're referring to this comment?

FWIW, I'm not seeing any regressions when rolling back to upsertQueryData (as mentioned in that comment), just this issue with upsertQueryEntries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants