Skip to content

Unable to use more than one apps with QueryClientProvider on page #1764

@NZainchkovskiy

Description

@NZainchkovskiy

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:

  1. Build 2 apps with example from here: https://codesandbox.io/s/github/tannerlinsley/react-query/tree/master/examples/simple
  2. 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).
  3. Serve this overall html (I did just serve -s build).
  4. 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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions