Skip to content

Run selectors twice in development to warn for memoization failures #611

Closed
@markerikson

Description

@markerikson

This one has been asked about for a while, particularly by @theKashey :

The idea is that users sometimes end up writing badly-written selectors that accidentally recalculate the results every time. This is primarily due to badly-written input functions, such as:

createSelector(
  state => ({ foo: state.foo, bar: state.bar }), 
  ({ foo, bar }) => ({result: foo + bar})
)

Since the input function always returns a new object, the output function will always run and return a new reference.

Probably the simplest thing we can do here would be to double-run the input functions twice and verify that the results are shallow equal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions