Skip to content

fix(query): prevent onQueryStarted from triggering at end-of-list#5182

Open
joseph0926 wants to merge 2 commits intoreduxjs:masterfrom
joseph0926:fix/infinite-query-onQueryStarted-end-of-list
Open

fix(query): prevent onQueryStarted from triggering at end-of-list#5182
joseph0926 wants to merge 2 commits intoreduxjs:masterfrom
joseph0926:fix/infinite-query-onQueryStarted-end-of-list

Conversation

@joseph0926
Copy link

Fixes #5167

Summary

When fetchNextPage() or fetchPreviousPage() is called at end-of-list (when getNextPageParam/getPreviousPageParam returns undefined), the thunk was still executing and triggering onQueryStarted with stale cached data.

To solve the problem added an early bail-out in the thunk's condition function -> to check if the next/previous page actually exists before processing any action.

Changes

  • Added direction check in buildThunks.ts condition function
  • Added test case for the fix
  • Updated existing test expectation (removed isFetchingPreviousPage: true when no previous page exists)

Test

  • yarn test
  • yarn type-tests
  • yarn eslint

@codesandbox
Copy link

codesandbox bot commented Jan 15, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 15, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 475a8e3:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

@netlify
Copy link

netlify bot commented Jan 15, 2026

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

Name Link
🔨 Latest commit 475a8e3
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/696f6186922ed80008fea6b0
😎 Deploy Preview https://deploy-preview-5182--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@aryaemami59 aryaemami59 added the RTK-Query Issues related to Redux-Toolkit-Query label Jan 20, 2026
@joseph0926
Copy link
Author

475a8e3

The tests added in the previous commit seemed slightly insufficient, so I added additional test code for possible edge cases.

For example, while only forward testing existed before, this commit adds verification for backward cases, as well as handling for skip operations and null values....

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.

fetchNextPage always triggering onQueryStarted, even when queryFulfilled already occured.

2 participants