blitz icon indicating copy to clipboard operation
blitz copied to clipboard

Fix queryKeyGeneration when using invalidateQuery

Open Zeko369 opened this issue 2 years ago • 4 comments

Closes: #3725

What are the changes and their implications?

Bug Checklist

  • [x] Fix invalidateQuery called with one param generating {json: undefined} as param

Feature Checklist

Zeko369 avatar Aug 14 '22 20:08 Zeko369

🦋 Changeset detected

Latest commit: 2a10e378f6f456a3e7d006392c860918b351586e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@blitzjs/rpc Patch
blitz Patch
@blitzjs/next Patch
@blitzjs/auth Patch
@blitzjs/codemod Patch
@blitzjs/recipe-base-web Patch
@blitzjs/recipe-bulma Patch
@blitzjs/recipe-bumbag-ui Patch
@blitzjs/recipe-chakra-ui Patch
@blitzjs/recipe-emotion Patch
@blitzjs/recipe-gh-action-yarn-mariadb Patch
@blitzjs/recipe-gh-action-yarn-postgres Patch
@blitzjs/recipe-ghost Patch
@blitzjs/recipe-graphql Patch
@blitzjs/recipe-logrocket Patch
@blitzjs/recipe-material-ui Patch
@blitzjs/recipe-next-ui Patch
@blitzjs/recipe-passenger Patch
@blitzjs/recipe-quirrel Patch
@blitzjs/recipe-reflexjs Patch
@blitzjs/recipe-render Patch
@blitzjs/recipe-secureheaders Patch
@blitzjs/recipe-stitches Patch
@blitzjs/recipe-styled-components Patch
@blitzjs/recipe-tailwind Patch
@blitzjs/recipe-theme-ui Patch
@blitzjs/recipe-vanilla-extract Patch
@blitzjs/config Patch
@blitzjs/generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Aug 14 '22 20:08 changeset-bot[bot]

@beerose invalidateQuery(a) if a is [queryName] it revalidates everything regardless of arguments, while [queryName, params] revalidates a specific params.

So the || {} would only invalidate that if the params were {} for the query itself, so technically it would work but it wouldn't work the same way as tanstack/query itself

Zeko369 avatar Aug 15 '22 07:08 Zeko369

Actually what we want is this

useQuery(getUser, undefined) // get dummy user
useQuery(getUser, 10)

Having undefined / 10 and in that case you have

invalidateQuery(getUser) // all get user queries
invalidateQuery(getUser, undefined) // just the first one -> so dummy user
invalidateQuery(getUser, 10) // invalidate user 10

And the PR currently doesn't do that so I'll fix it now and then re-request your review

Zeko369 avatar Aug 15 '22 08:08 Zeko369

Is there a workaround for this while we wait for a release with this fix?

Jaxenormus avatar Sep 04 '22 19:09 Jaxenormus

Hey @Zeko369, wanted to follow up on this. We were talking about adding tests. Are you still up for adding them?

beerose avatar Sep 27 '22 12:09 beerose

@beerose unit tests for getKey and integration tests with actual invalidation 🚀 added

Zeko369 avatar Sep 30 '22 13:09 Zeko369