queryCache.findAll() returns wrapped iterable instead of array — breaks standard invalidation APIs
#10257
Replies: 2 comments
-
|
@nicolas-chalet-wmx Thanks for the detailed environment notes (especially WebView-only repro). queryCache.findAll() returning a non-array-like wrapper in one build target strongly suggests an interop/transpilation mismatch (iterator/polyfill/runtime) rather than expected Query API behavior. Quick isolation steps:
If this confirms environment-specific iterator behavior, maintainers can likely suggest the most compatible workaround. References: |
Beta Was this translation helpful? Give feedback.
-
|
You have diagnosed it correctly: module duplication. Your library and the host app are resolving to different instances of This is especially common in WebViews where the library is pre-bundled with react-query inlined, while the host app has its own copy. The real fix is deduplication. In your library's // library vite.config.ts
export default defineConfig({
build: {
lib: { entry: "src/index.ts", formats: ["es"] },
rollupOptions: {
external: ["@tanstack/react-query", "react", "react-dom"],
},
},
})If you cannot change the library, the host app can force deduplication: Your |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Environment:
@tanstack/react-queryv5.90.2Description:
We're building a library that uses react-query and is consumed by a host application. In certain build configurations (mobile WebViews), we observe unexpected behavior:
We suspect this is due to module duplication where our library and the host app resolve to different instances of
@tanstack/react-query.Impact:
Due to this issue, we cannot use the standard react-query APIs for cache management:
This forces us to bypass the intended API and work directly with
Queryinstances, which feels brittle and may break with future versions.Questions:
Query.invalidate()/Query.reset()/Query.fetch()a supported pattern, or are we relying on internal implementation details?Workaround:
We currently normalize the result by checking if the first element is iterable:
Beta Was this translation helpful? Give feedback.
All reactions