Skip to content

Documentation unclear that weakMapMemoize is now the default memoizer #753

@audi2014

Description

@audi2014

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:

  1. 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
  }
)
  1. Developers may not realize the default changed: Those familiar with Reselect v4.x (where lruMemoize/defaultMemoize was default) may not realize the behavior has changed.

  2. Migration implications unclear: The difference between lruMemoize (cache size: 1) and weakMapMemoize (unlimited cache) has significant performance and memory implications that aren't highlighted.

Suggested Improvements

  1. Add a callout to the main documentation stating:

    ⚠️ Note: As of v5.0, weakMapMemoize is the default memoizer. Previous versions used lruMemoize with a cache size of 1.

  2. Update examples to either:

    • Remove the explicit memoize/argsMemoize options (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
    }

Current Versions Affected

  • v5.x documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions