fix(query): skip fetch when infinite query trigger is called with skipToken#5334
Open
xianjianlf2 wants to merge 2 commits into
Open
fix(query): skip fetch when infinite query trigger is called with skipToken#5334xianjianlf2 wants to merge 2 commits into
skipToken#5334xianjianlf2 wants to merge 2 commits into
Conversation
…pToken When an infinite query hook is skipped (via `skipToken` or the `skip` option), calling `fetchNextPage()`/`fetchPreviousPage()` (or the lazy `trigger`) dispatched `initiate(skipToken)`, which fired a real request using `skipToken` as the query arg and created a bogus cache entry. Guard the shared trigger so a skipped arg unsubscribes any previous promise and bails out without dispatching, matching the auto-subscription behavior. Closes reduxjs#5028
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
skipToken
@reduxjs/rtk-codemods
@rtk-query/codegen-openapi
@rtk-query/graphql-request-base-query
@reduxjs/toolkit
commit: |
Author
|
Note on the two red Test Types: TS next checks: they fail identically on upstream master — run 29339252283 (commit 58e8cfe, before this PR's CI run) shows the same 5 errors with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an infinite query hook is skipped (via
skipTokenor theskipoption), callingfetchNextPage()/fetchPreviousPage()(or the lazytrigger) dispatchedinitiate(skipToken), which fired a real request usingskipTokenas the query arg and created a bogus cache entry.Fix
Guard the shared infinite-query trigger so that when it is called with a skipped
arg(skipToken), it unsubscribes any previous promise and bails out without dispatching, matching the auto-subscription behavior. This makesfetchNextPage()/fetchPreviousPage()on a skipped hook a no-op instead of firing a request withskipTokenas the query arg.Testing
Added a test in
packages/toolkit/src/query/tests/buildHooks.test.tsxverifying that triggeringfetchNextPage()/fetchPreviousPage()on a skipped infinite query does not dispatch a request or create a cache entry.Closes #5028