-
Notifications
You must be signed in to change notification settings - Fork 662
Description
as a developer i found mention about true behavior of memoization here https://reselect.js.org/introduction/v5-summary#breaking-changes
But i found this page only after playing with reselect in sandboxes. I was confused why this example may no effect: https://reselect.js.org/api/weakmapmemoize/#examples
llm generated:
Problem
The documentation doesn't clearly state that weakMapMemoize is now the default memoization function for createSelector (changed in commit 1ffd434).
This causes confusion because:
- Examples show redundant configuration: The weakMapMemoize example and API documentation show:
const selectItemsByCategory = createSelector(
[
(state: RootState) => state.items,
(state: RootState, category: string) => category
],
(items, category) => items.filter(item => item.category === category),
{
memoize: weakMapMemoize, // ← This is already the default
argsMemoize: weakMapMemoize // ← This is also already the default
}
)-
Developers may not realize the default changed: Those familiar with Reselect v4.x (where
lruMemoize/defaultMemoizewas default) may not realize the behavior has changed. -
Migration implications unclear: The difference between
lruMemoize(cache size: 1) andweakMapMemoize(unlimited cache) has significant performance and memory implications that aren't highlighted.
Suggested Improvements
-
Add a callout to the main documentation stating:
⚠️ Note: As of v5.0,weakMapMemoizeis the default memoizer. Previous versions usedlruMemoizewith a cache size of 1. -
Update examples to either:
- Remove the explicit
memoize/argsMemoizeoptions (since they're redundant) - Add comments explaining that this is showing explicit configuration but isn't necessary:
{ // These are the defaults in v5.0+, shown here for clarity: memoize: weakMapMemoize, argsMemoize: weakMapMemoize }
- Remove the explicit
Current Versions Affected
- v5.x documentation