-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(QueryCache): Use default configuration used for QueryCache instance for context #808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(QueryCache): Use default configuration used for QueryCache instance for context #808
Conversation
…ltConfigRef by default
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/hwdovaqmd |
| export function useConfigContext() { | ||
| return React.useContext(configContext) || defaultConfigRef.current | ||
| const queryCache = useQueryCache() | ||
| return React.useContext(configContext) || queryCache.configRef.current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default queryCache.configRef will be defaultConfigRef out-of-the-box unless you're using makeQueryCache.
|
I am currently "integration" testing this in our repo. |
…ltConfigRef by default
…yub/react-query into fix/default-config-merge
|
Just seeing weird issues locally when testing where the query cache I am creating and providing via edit: not sure why GH thinks there are 58 changes after rebasing, those aren't actual changes from edit 2: there we go 🤷♂️ |
|
OK, the issue is that there were two major bugs with |
|
Alrighty, this is working now as I would expect! |
|
Fantastic! |
|
🎉 This PR is included in version 2.5.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Context
See test cases but when using
useQuerywith no config provider and a custom query cache provider, thedefaultConfigwas not being merged correctly inqueryCache.buildQuery.A previously failing test:
useConfigContextwas falling back todefaultConfigRefbut when usingmakeQueryCache, the ref is not updated (on purpose) when merging indefaultConfig.Now the actual merged
configReffor the query cache is exposed so that we can access it inuseConfigContext.Wrong
queryCachevariable being passedI fixed another two issues with
buildQueryandnotifyGlobalListenersthat was passing thequeryCachemodule variable instead ofthisin the new refactored TS code.Exposing the config ref
I'm not sure whether you want it exposed off the instance like that or through some other means (since this would also consumers to mess with it?). However, it does address the issue.I am exposing it through
QueryCache.getDefaultConfigwhich could be used to freeze or clone the config to prevent mutation.Exposing it like this would mean:
I can document this as a new API, I could freeze it, whatever we think would make sense. We just need to get a reference to the merged queryCache-specific config.
Changes
useQueryCacheinuseConfigContextto fallback to queryCache'sconfigRefQueryCache.getDefaultConfig()methodqueryCacheref innotifyGlobalListenersqueryCacheref inbuildQuery