Closed Bardiamist closed 2 weeks ago
Thanks for reporting.
Does it only fail with '0'
and not with '1'
?
We would need a test case to fix the bug.
Looks it fails with any string when this string not changed between calls.
Not only strings. Also numbers and {}
leads to this problem.
I tied to create small repro many hours, copied many selectors. But it reproducing only on the project.
Maybe will continue try tomorow.
Any ideas would be helpful.
Selector uses another memoized selector.
We have some double selector tests, but the coverage may not be enough. For triple selector tests, test coverage would be lower.
I'm not sure if that helps.
Reproduced
const memoize = require('proxy-memoize').memoize;
const state1 = {
book1: {
staticProp: '5',
priceString: '10',
},
};
const state2 = {
book1: {
staticProp: '5',
priceString: '20',
},
};
const selectAllBooks = memoize((state) => Object.values(state));
const selectPriceString = memoize((
state,
) => state.book1.priceString);
const selectAdjustedPriceString = memoize((state) => {
const priceString = selectPriceString(state);
const problem = state.book1.staticProp;
return priceString;
});
selectAllBooks(state1);
console.log(selectAdjustedPriceString(state1));
console.log(selectAdjustedPriceString(state2));
node
version: 22.4.0
proxy-memoize
version: 3.0.0
Second console.log
should show 20
(not 10
)
Thanks for the reproduction. #101 adds the test case.
Please try: https://ci.codesandbox.io/status/dai-shi/proxy-memoize/pr/101 ☝️ Find "Local Install Instructions"
I use yarn 4 so used yarn add proxy-memoize@https://pkg.csb.dev/dai-shi/proxy-memoize/commit/4aac6ae2/proxy-memoize/_pkg.tgz
This case fixed, thanks :tada:
But my initial problem still exists :cry: I'll back if will find way to create a repro.
You can start from this
Second expected output is 0
Here is extended example which more close to my problem
Third expected output is 10
Strange that if use state1
instead of state3
then it has affect
Okay, let me merge #101 and tackle the new one separately.
Simplified example
Can you simplify it a bit more? A test case should be small, and a minimal reproduction helps to investigate the bug.
I simplified as possible
Yeah, but my gut feeling is there should be a smaller repro to reveal the bug. Maybe, it has to be created from a different angle, instead of simplifying the current code.
I haven't read it very carefully yet, but one possibility is double nested memoize works, but triple nested memoize can fail.
Yeah, but my gut feeling is there should be a smaller repro to reveal the bug.
You can try to remove something then bug will stop to reproduce
Maybe, it has to be created from a different angle, instead of simplifying the current code.
Rare case. Was difficult to find related selectors and call in right order. Simplified as possible and anonymized data.
I haven't read it very carefully
Should be easy to read on books example
one possibility is double nested memoize works, but triple nested memoize can fail.
Better if selectors will be recalled than return wrong data
You can try to remove something then bug will stop to reproduce
Done: #102
Please open a new issue if you still find a bug.
Cool, I tested, all problems fixed, looks good, thank you! :tada:
That's great to hear.
FYI, here's the simplified repro: https://github.com/dai-shi/proxy-memoize/blob/e2aa105310e71df13f901bb7d701d6ee2d9aa27c/tests/issue_100.spec.ts#L53-L87
Hey, I have reproducible problem on big project but I still can't create small example.
Essence of the problem:
proxy-memoize
detects changes in the selector and recall as expected. But if this selector will additionally use some string likestate.books[id].priceString
(wherepriceString
is'0'
) thenproxy-memoize
doesn't recall this selector.Additional info: Selector uses another memoized selector. If don't memoize internal selector then no problems with
'0'
strings.Any ideas?