toomuchdesign / re-reselect

Enhance Reselect selectors with deeper memoization and cache management.
MIT License
1.08k stars 46 forks source link

What can cause cachedSelector to recompute despite identical keySelector? #285

Closed Nantris closed 1 month ago

Nantris commented 1 month ago

Do you want to request a feature or report a bug?

Possible bug?

What is the current behaviour?

Returning identical keySelector still recomputes constantly

What is the expected behaviour?

Identical keySelector output causes recompute to be skipped.

Steps to Reproduce the Problem

Unknown exactly, but something like this is what we use:

  keySelector: state => {
    const {
      a = false,
      b = '',
      c = false,
      d = true,
      e = true,
      f = false,
      g,
    } = getOpts(state);

    return `${a}::${b}::${c}::${d}::${e}::${f}::${g}`;
  },

  cacheObject: new FifoObjectCache({ cacheSize: 10 }),
});

Specifications

toomuchdesign commented 1 month ago

Hi @Nantris, in order to provide support a minimal repro is needed. Chances are that something in user land is the cause of the issue you describe.

Nantris commented 1 month ago

@toomuchdesign thanks for your reply.

I'll see what I can put together - but I wonder if you have any general/generic advice regarding userland? I can't imagine what else could be at cause here, except having the wrong versions of reselect or redux for the version of re-reselect that we're using (but I confirmed that not to be the case.)

toomuchdesign commented 1 month ago

Please not that the expectation provided above is uncorrect:

Identical keySelector output causes recompute to be skipped.

Identical keySelector causes the same reselect selector to be called.

Given a keySelector, the expected reselect selector will be called with provided inputSelectors.