T
TanStack4y ago
unwilling-turquoise

Unexpected re-renders, notifyOnChangeProps question

Hi, i have a question about notifyOnChangeProps. Docs says that the default behavior is tracked, but I see some unexpected re-renders and I'm trying to understand why they are happening. Please take a look at this example: https://codesandbox.io/s/quizzical-montalcini-jm2dyf?file=/src/index.js I expect to see 2 renders: first when data is undefined and second when the data comes from the queryFn. Somehow i see 3 renders and i can't understand why.
CodeSandbox
quizzical-montalcini-jm2dyf - CodeSandbox
quizzical-montalcini-jm2dyf using @tanstack/react-query, react, react-dom, react-scripts
No description
5 Replies
stormy-gold
stormy-gold4y ago
interesting, yeah. I'd also only expect two renders. The second call to the queryFn is because Item mounts and staleTime is zero, so that's okay. but that shouldn't trigger Items to re-render because it's only interested in data, and that didn't change
unwilling-turquoise
unwilling-turquoiseOP4y ago
indeed, but somehow it happens. Also, my experiments show that if i put staleTime to 1000 or infinite 3rd re-render doesn't happen.
stormy-gold
stormy-gold4y ago
yes, that is also understandable for me: with staleTime, the mount of Item won't trigger a re-fetch. So you'll only see queryFn once as well. if you set refetchOnWindowFocus: true and start to focus the window a bunch (with default staleTime zero), you'll start to see a bunch of queryFn logs, but no re-render. That's the behaviour I expected when the mount of Item triggers another fetch but for some reason, we inform the Items observer that it needs to re-render. Not sure why. Can you file an issue?
unwilling-turquoise
unwilling-turquoiseOP4y ago
yes, will do, tnx a lot for help
unwilling-turquoise
unwilling-turquoiseOP4y ago
GitHub
Unexpected re-renders, notifyOnChangeProps question · Issue #4570 ·...
Describe the bug Hi, i have a question about notifyOnChangeProps. Docs says that the default behavior is tracked, but I see some unexpected re-renders and I'm trying to understand why they ...

Did you find this page helpful?