fix(query): don't reset keepUnusedDataFor on condition-skipped queries#5343
Open
veksa wants to merge 1 commit into
Open
fix(query): don't reset keepUnusedDataFor on condition-skipped queries#5343veksa wants to merge 1 commit into
keepUnusedDataFor on condition-skipped queries#5343veksa wants to merge 1 commit into
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
veksa
force-pushed
the
fix/query-keep-unused-data-for-4480
branch
from
July 20, 2026 11:14
dbd09f8 to
d56b852
Compare
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@reduxjs/rtk-codemods
@rtk-query/codegen-openapi
@rtk-query/graphql-request-base-query
@reduxjs/toolkit
commit: |
EskiMojo14
approved these changes
Jul 20, 2026
Collaborator
|
the changes make sense to me, but i'd like a second pair of eyes on this |
veksa
force-pushed
the
fix/query-keep-unused-data-for-4480
branch
from
July 20, 2026 12:50
d56b852 to
4aaa709
Compare
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.
Fixes #4480
If you keep dispatching
initiatewith{ subscribe: false }for an arg that'salready cached, the data never gets removed. Each call pushes the expiry back, so
keepUnusedDataForeffectively turns into "keep forever" as long as somethingpolls that endpoint without subscribing.
Repro from the issue:
Cause
The cache-collection middleware reschedules the removal timer whenever
canTriggerUnsubscribematches, and it was matchingqueryThunk.rejectedas awhole.
When
initiate(..., { subscribe: false })hits a fresh cache entry, the thunk'sconditionreturnsfalseand bails out before running. But the thunk usesdispatchConditionRejection: true, so it still dispatches arejectedaction —one tagged with
meta.condition === true. That made a plain cache hit look likea finished request: the pending removal timeout got cleared and a fresh one
started, even though nothing was fetched and no subscription changed.
Fix
Ignore condition-based rejections when deciding whether to reschedule cleanup. A
query that bailed out via
conditionnever ran and never touched asubscription, so it shouldn't restart the removal timer. Real failures of
unsubscribed queries (
meta.condition === false) still schedule removal asbefore:
I also added a regression test that fires two
initiate({ subscribe: false })calls 30s apart and checks the entry is removed on the original deadline instead
of being pushed out.