Skip to content

fix(query): skip fetch when infinite query trigger is called with skipToken#5334

Open
xianjianlf2 wants to merge 2 commits into
reduxjs:masterfrom
xianjianlf2:fix/infinite-query-skiptoken-trigger-5028
Open

fix(query): skip fetch when infinite query trigger is called with skipToken#5334
xianjianlf2 wants to merge 2 commits into
reduxjs:masterfrom
xianjianlf2:fix/infinite-query-skiptoken-trigger-5028

Conversation

@xianjianlf2

Copy link
Copy Markdown

Problem

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.

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 makes fetchNextPage()/fetchPreviousPage() on a skipped hook a no-op instead of firing a request with skipToken as the query arg.

if (arg === skipToken) {
  unsubscribePromiseRef(promiseRef)
  promiseRef.current = undefined
  return promiseRef.current as unknown as InfiniteQueryActionCreatorResult<any>
}

Testing

Added a test in packages/toolkit/src/query/tests/buildHooks.test.tsx verifying that triggering fetchNextPage()/fetchPreviousPage() on a skipped infinite query does not dispatch a request or create a cache entry.

Closes #5028

…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
@codesandbox

codesandbox Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@netlify

netlify Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit bfdfcce
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/6a56ebe42b9a8b00085b50bd
😎 Deploy Preview https://deploy-preview-5334--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@aryaemami59 aryaemami59 changed the title fix(query): skip fetch when infinite query trigger is called with skipToken fix(query): skip fetch when infinite query trigger is called with skipToken Jul 14, 2026
@aryaemami59 aryaemami59 added the RTK-Query Issues related to Redux-Toolkit-Query label Jul 14, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@reduxjs/rtk-codemods

npm i https://pkg.pr.new/@reduxjs/rtk-codemods@bfdfcce -D
yarn add https://pkg.pr.new/@reduxjs/rtk-codemods@bfdfcce.tgz -D
pnpm add https://pkg.pr.new/@reduxjs/rtk-codemods@bfdfcce.tgz -D
bun add https://pkg.pr.new/@reduxjs/rtk-codemods@bfdfcce.tgz -D

@rtk-query/codegen-openapi

npm i https://pkg.pr.new/@rtk-query/codegen-openapi@bfdfcce -D
yarn add https://pkg.pr.new/@rtk-query/codegen-openapi@bfdfcce.tgz -D
pnpm add https://pkg.pr.new/@rtk-query/codegen-openapi@bfdfcce.tgz -D
bun add https://pkg.pr.new/@rtk-query/codegen-openapi@bfdfcce.tgz -D

@rtk-query/graphql-request-base-query

npm i https://pkg.pr.new/@rtk-query/graphql-request-base-query@bfdfcce -D
yarn add https://pkg.pr.new/@rtk-query/graphql-request-base-query@bfdfcce.tgz -D
pnpm add https://pkg.pr.new/@rtk-query/graphql-request-base-query@bfdfcce.tgz -D
bun add https://pkg.pr.new/@rtk-query/graphql-request-base-query@bfdfcce.tgz -D

@reduxjs/toolkit

npm i https://pkg.pr.new/@reduxjs/toolkit@bfdfcce -D
yarn add https://pkg.pr.new/@reduxjs/toolkit@bfdfcce.tgz -D
pnpm add https://pkg.pr.new/@reduxjs/toolkit@bfdfcce.tgz -D
bun add https://pkg.pr.new/@reduxjs/toolkit@bfdfcce.tgz -D

commit: bfdfcce

@xianjianlf2

Copy link
Copy Markdown
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 typescript@7.1.0-dev.20260714.1: buildHooks.ts(1859) TS2769 and the mapBuilders.test-d.ts TS2578/TS2769 set. This PR doesn't touch either location (its only src change is around line 2103), so the failures are nightly-TypeScript breakage unrelated to this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RTK-Query Issues related to Redux-Toolkit-Query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

skipToken is passed into my infiniteQuery as a queryArg

2 participants