-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Describe the bug
I have a monorepo with yarn 3 workspaces consisting of the following (as well as other components):
contracts
which uses Orval to create typed react-query hooks from OpenAPIui
, a next.js project that has a workspace dependency on contracts and is using above hooks
The only direct dependencies on react-query are through contracts
, my UI project does not directly use react-query.
I'm now running into a few issues to do with module resolution, and am not sure how much of this relates to yarn, workspaces, react-query, or next magic.
React-query cannot find QueryProvider
If I make react-query a peer dependency of contracts
, then initialize react-query
in my next project (set a query provider, etc), then the hooks that use react-query under the hood from contracts
do not find the QueryClient. It appears to "see" its own version of react-query even though this is a peer dependency of contracts and I provide it as a direct dependency in ui.
I am able to work around this by having contracts
instead directly depend on react-query
, and re-export the symbols from react-query (export * from 'react-query'). This appears to give the hooks in
contracts` access to the same react-query and the context / query provider is found.
... or at least it was. Without any meaningful changes (I'm working on pinning down the exact change), I am no longer able to do it this way, as react-query now fails to find react
. Inside the compiled code of react-query
, I am getting React
as an undefined symbol and this line blows up var defaultContext = /*#__PURE__*/React.createContext(undefined);
iin react/QueryClientProvider.js
I appreciate that this isn't much to go on, but in general, what is the recommended method for providing custom hooks based on react-query in a library in terms of dependencies and configuration of the query client?
Your minimal, reproducible example
N/A
Steps to reproduce
- Build a library that leverages react-query in custom hooks with react-query as a peer dependency
- Use the library from above in a different project, providing react-query as a direct dependency
- Configure react-query with a QueryClientProvider in the dom where the hooks from 1 are being used
Expected behavior
React-query can "see" the context and query provider wired up in the react DOM, even when using peer dependencies and the react-query library is provided as a dependency form the parent project.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: Ubuntu 20
- Yarn: 3.2.0
- Next.js: 12.1.6
react-query version
3.39.0
TypeScript version
4.6.4
Additional context
No response