fix(query): prevent onQueryStarted from triggering at end-of-list#5182
fix(query): prevent onQueryStarted from triggering at end-of-list#5182joseph0926 wants to merge 2 commits into
onQueryStarted from triggering at end-of-list#5182Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
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:
|
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
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.... |
onQueryStarted from triggering at end-of-list
themavik
left a comment
There was a problem hiding this comment.
Gating initiate when getNextPageParam/getPreviousPageParam returns null stops the extra onQueryStarted at the tail—matches the new tests. nit: the guard only runs when cachedData.pages.length is truthy; if an infinite query ever has a zero-page cached shape you might still dispatch—probably unreachable, but worth a glance.
Fixes #5167
Summary
When
fetchNextPage()orfetchPreviousPage()is called at end-of-list (whengetNextPageParam/getPreviousPageParamreturnsundefined), the thunk was still executing and triggeringonQueryStartedwith stale cached data.To solve the problem added an early bail-out in the thunk's
conditionfunction -> to check if the next/previous page actually exists before processing any action.Changes
buildThunks.tscondition functionisFetchingPreviousPage: truewhen no previous page exists)Test