-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Describe the bug
In my scenario I need to host more than one react application on one page.
Each of app uses react-query v3, app wrapped with QueryClientProvider (I can reproduce it with CRA apps with just your "overview" sample code (https://codesandbox.io/s/github/tannerlinsley/react-query/tree/master/examples/simple)).
When I open page with these apps, only one of them running fine, and others fails with error:
No QueryClient set, use QueryClientProvider to set one
Maybe it's because of using window.ReactQueryClientContext for context storage of app, what makes impossible to use many react-query context on one page with many apps (https://github.com/tannerlinsley/react-query/blob/master/src/react/QueryClientProvider.tsx#L9).
If I use just one app with many QueryClientProviders it's works ok.
If you can suggest any workarounds for this issue, I will appreciate it. Thank you.
To Reproduce
Steps to reproduce the behavior:
- Build 2 apps with example from here: https://codesandbox.io/s/github/tannerlinsley/react-query/tree/master/examples/simple
- Host these 2 apps with one html page (I just build two CRA apps and then add div and scripts from one app index.html to another).
- Serve this overall html (I did just serve -s build).
- See error. First app crashes, but second runs fine.
Expected behavior
Every separate apps runs without react-query related errors and with react-query functionality.
Additional context
I tried to add some timeout for render of second app, and it's works but only for the first serve of html. Than, after page reload errors returns.
setTimeout(() => {
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("app2")
);
}, 1000);