You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
weakMapMemoize with resultEqualityCheck is provided empty objects for first call. #693
Hi! Thanks for all the great QOL improvements in Reselect 5, however I've found a pretty major issue with the resultEqualityCheck option when using the weakMapMemoize memoization. It calls the resultEqualityCheck even if it is the first time the selector has run. This wouldn't be too bad, however this first call is called with empty objects instead of the actual result of the selector. Please see the example below. Obviously this is a bit of a contrived example using strings, but things get pretty hairy if you expect the result to be a Set or another complex object.
constfirstMessageSelector=createSelector([(messages)=>messages[0]],(message)=>`${message}!!!`,{memoizeOptions: {resultEqualityCheck: (a,b)=>{console.log("resultEqualityCheck:",{ a, b });returna===b;},},});constone=firstMessageSelector(["one","two"]);console.log("one:",one);consttwo=firstMessageSelector(["two","three"]);console.log("two:",two);
hmm, this is a good point - the resultEqualityCheck is typed to only expect the result of the memoized function (edit: it's actually typed as any), but the inputStabilityCheck uses the same memoizeOptions and memoize with a different function, one that always returns a new empty object. This is important for how the check works.
I'm not sure of the best fix for this, but I agree it's not great.
Really excited about reselect v5 but +1 on this being upgrade blocking 😞 . We almost guarantee a (development-only) runtime break when resultEqualityCheck does any sort of complex work. (and disabling inputStabilityCheck feels like a band-aid fix)
I could be missing something @EskiMojo14, but this is the code I would have expected for inputStabilityCheck:
we need to treat memoizeOptions as an opaque value, because it could be anything depending on what memoizer is being used. For example, weakMapMemoize's options don't have an equalityCheck property.
The only way (I can think of) that we can accurately assess that the memoizer, when configured the same way as it is for the output selector, considers the inputs to be different is to do what we do - memoize a separate function that always returns a new reference, with the exact same options used when memoizing the output selector.
Activity
EskiMojo14 commentedon Jan 31, 2024
hmm, this is a good point -
the(edit: it's actually typed asresultEqualityCheckis typed to only expect the result of the memoized functionany), but theinputStabilityCheckuses the same memoizeOptions and memoize with a different function, one that always returns a new empty object. This is important for how the check works.I'm not sure of the best fix for this, but I agree it's not great.
braeden commentedon Feb 11, 2024
Really excited about
reselectv5 but +1 on this being upgrade blocking 😞 . We almost guarantee a (development-only) runtime break whenresultEqualityCheckdoes any sort of complex work. (and disablinginputStabilityCheckfeels like a band-aid fix)I could be missing something @EskiMojo14, but this is the code I would have expected for
inputStabilityCheck:I don't think
resultEqualityCheckormaxSizeshould matter/not sure why we need to setup the fullmemoizeagain?If this ^ doesn't work, maybe the best option is just omitting
resultEqualityCheckfrom the...memoizeOptionsspread.EskiMojo14 commentedon Feb 11, 2024
we need to treat memoizeOptions as an opaque value, because it could be anything depending on what memoizer is being used. For example, weakMapMemoize's options don't have an
equalityCheckproperty.The only way (I can think of) that we can accurately assess that the memoizer, when configured the same way as it is for the output selector, considers the inputs to be different is to do what we do - memoize a separate function that always returns a new reference, with the exact same options used when memoizing the output selector.
uncaught commentedon Aug 20, 2025
Just stumbled over this, Why is this issue still open? Does #699 not fix it?