docs: clarify how to fully clear a selector's cache (#569) - #760
Open
veksa wants to merge 2 commits into
Open
Conversation
✅ Deploy Preview for reselect-docs canceled.
|
|
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. |
veksa
force-pushed
the
fix/569-clearing-selector-cache
branch
from
July 27, 2026 07:07
4f8bd91 to
4a7ff20
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.
Summary
Closes #569.
A memoized selector keeps two separate caches because of Reselect's
two-stage "cascading" memoization:
argsMemoizecache for the arguments passed to the output selector,attached to the selector itself (
selector.clearCache());memoizecache for the input selectors' results, attached tomemoizedResultFunc(selector.memoizedResultFunc.clearCache()).selector.clearCache()only clears the first one. This trips people up whenthey try to reset a selector between tests and see stale memoized results — the
exact confusion reported in #569.
Note: the original type error from that issue was on v4. On v5 the types are
already correct — both
.clearCache()accesses type-check on default andlruselectors (verified with
tsc). So the real gap was purely documentation; thisPR documents the behavior and adds a regression type test to lock it in.
Changes
Docs
FAQ.mdx– add a note in "How do I test a selector?" explaining the twocaches and showing how to fully reset a selector between tests.
api/createSelector.mdx– add a "Clearing the cache" note under the OutputSelector Fields table.
Types
src/types.ts– expand the JSDoc onmemoizedResultFuncandclearCachesothe dual-cache behavior shows up in IDE hovers.
typescript_test/argsMemoize.typetest.ts– add a type test asserting thatclearCache/resultsCount/resetResultsCountexist on both a defaultselector and its
memoizedResultFunc.Testing
tsc --noEmit -p typescript_test/tsconfig.jsonpasses.