zodios icon indicating copy to clipboard operation
zodios copied to clipboard

zodios-react key from useXXX is differ from getKeyByXXX

Open QzCurious opened this issue 3 years ago • 6 comments

The Bug

Here is a reproduction CodeSandbox.

The bug is caused by explicitly passing undefined as config to a useXXX. But not on getKeyByXXX

Workaround

Explicitly pass {} to getKeyByXXX as config.

The workaround would NOT work if I try to getKeyByXXX on a immutable query. It's because useImmutableQuery additionally append body to its queryKey.

The Root Cause

For useXXX

  1. useQuery picks params, queries and use it to produce the queryKey.
  2. The pick function would at least return an empty object even if the obj is undefined
  3. The explicit undefined config of useXXX produce a {} in its queryKey

For getKeyByXXX

It essentially do the same as useXXX. But it checks if config is passed and then make it part of queryKey.

Possible Solution

At first, I believe there is a bug on pick implementation. If the obj is undefined, it should return undefined, too.

Fix the Mismatch Behavior between useXXX and getKeyByXXX.

Both these two function needs to derive queryKey from config. So either copy paste the code one another . Or an helper method might be cleaner.

QzCurious avatar Jan 09 '23 05:01 QzCurious

Hope the context is enough for you to fix this. I'm sorry that currently I don't have time to do the PR.

QzCurious avatar Jan 09 '23 05:01 QzCurious

Thank you for taking the time to report this issue and also to create a reproductible example. This will be fixed today as it should be an easy fix. to evoid issues in the future, i'll share the code between the two.

ecyrbe avatar Jan 10 '23 18:01 ecyrbe

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 16 '23 00:02 stale[bot]

Sorry for delay, not as easy as i thought.

ecyrbe avatar Feb 23 '23 06:02 ecyrbe

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 25 '23 14:03 stale[bot]

Is there any update on this? Really liking the library so far but this "breaks" my hydration setup.

I investigated it a bit and it seems like in the getKeyByX methods there is a check whether config is undefined or not. But useQuery does not have that check. Could this be the issue?

not-paul-v avatar Apr 02 '23 19:04 not-paul-v