Closed IPWright83 closed 1 year ago
Thanks for reporting.
I don't think many people use memoizeWithArgs
compared to memoize
, so it can be a bug. If it's a bug, it should probably be reproducible with a few lines of code.
Can anyone help reproducing it minimally from the provided repo?
@dai-shi I'll give it a quick try and see if I can make any progress. Would you recommend using memoize
and using an object instead then?
getScale: memoize(({ state: IState, field: string, type: "plot" | "brush" }) => {
If you look at the code, it's basically the same.
Not having much joy with a simple replication https://codesandbox.io/s/nifty-sea-pcycvm?file=/src/proxy-memoize.test.ts this seems to be working fine. Any more thoughts on how I might debug this further?
Nevermind I think I'm being daft. I just realised that the 3rd party function I'm using underneath is stateful 🤦🏻♂️
I'm trying to use
memoizeWithArgs
and I'm finding that it's returning the wrong results - essentially returning results for a different set of args.I'm calling it like so:
It works to start with, returning correct values (see the
[70, 760]
in the watch window).Once a call with a different type (brush) is used, I correctly get different results:
However each call there-after that has the same args as the first call (using
"plot"
, now starts returning the cached result from the call using"brush"
).I'm trying to debug it, but not having a huge amount of joy so far.
To reproduce the easiest way is to currently:
pnpm install
from the root (you'll needpnpm
installed to your system first)pnpm build
cd packages/react
pnpm storybook
http://localhost:6006/?path=/story/xycharts-line--line-with-brush
in a browserSVGLine
in the browser source and add a breakpoint at the console log (line 24).At this point you should be able to see the incorrect calls. You can verify it's being memoised (and not the selector logic) by placing breakpoints in
chartSelectors
lines 182 and 198.