{"version":3,"file":"foreign-client-warning.cjs","names":[],"sources":["../../src/query/foreign-client-warning.ts"],"sourcesContent":["/**\n * Internal, in its own file for the reason the AppBar warning is: a module that\n * exports a component may export nothing else without breaking Fast Refresh\n * (`react-refresh/only-export-components`), and the warn-once latch needs a\n * reset for tests to assert the warning more than once.\n */\nimport { QueryClient } from \"@tanstack/react-query\";\n\nimport { isDevBuild } from \"../utils/dev-mode\";\nimport { DUPLICATE_COPY_REMEDY } from \"../utils/duplicate-instance\";\n\n/** Set once the warning has printed, so a re-render does not bury the console. */\nlet warnedForeignClient = false;\n\n/**\n * Reset the warn-once latch. Test-only: the latch is module state, so a suite\n * asserting the warning more than once would otherwise see it only the first time.\n */\nexport function resetForeignClientWarning(): void {\n    warnedForeignClient = false;\n}\n\n/**\n * Warn when the `client` handed in was built by a different copy of\n * `@tanstack/react-query`.\n *\n * This prop is the one place the app's copy and the SDK's copy touch: the app\n * constructs a `QueryClient` and passes it in, and `QueryClientProvider` —\n * resolved from the SDK's copy — publishes it on *that* copy's context. Every\n * `useQuery` in the app then reads the app copy's context, finds nothing, and\n * throws `No QueryClient set, use QueryClientProvider to set one` while a\n * provider is plainly mounted three lines up. Nothing in that message points at\n * the duplicate, which is why it costs an afternoon.\n *\n * `instanceof` is the discriminator, and it is exactly the right one: two copies\n * define two distinct `QueryClient` classes, so a client from the other copy\n * duck-types perfectly and fails the identity check. The duck-type guard runs\n * first so the warning fires only on the shape that is actually a client —\n * without it, every hand-rolled test double would trip it.\n *\n * @param client - The client the caller passed, if any.\n */\nexport function warnOnForeignClient(client: QueryClient | undefined): void {\n    if (warnedForeignClient || client === undefined || !isDevBuild()) return;\n    if (client instanceof QueryClient) return;\n    const looksLikeClient =\n        typeof (client as Partial<QueryClient>).getQueryCache === \"function\" &&\n        typeof (client as Partial<QueryClient>).mount === \"function\";\n    if (!looksLikeClient) return;\n    warnedForeignClient = true;\n    console.warn(\n        \"[tempest-react-sdk] <QueryProvider client={...} /> received a QueryClient \" +\n            \"built by a different copy of @tanstack/react-query. The SDK publishes it on \" +\n            \"its own copy's context, so the app's `useQuery` calls will throw \" +\n            '\"No QueryClient set\" even though this provider is mounted. ' +\n            DUPLICATE_COPY_REMEDY,\n    );\n}\n"],"mappings":"6HAYA,IAAI,EAAsB,GA8B1B,SAAgB,EAAoB,EAAuC,CACnE,IAAuB,IAAW,IAAA,IAAc,EAAA,WAAW,IAC3D,aAAkB,EAAA,aAElB,OAAQ,EAAgC,eAAkB,YAC1D,OAAQ,EAAgC,OAAU,aAEtD,EAAsB,GACtB,QAAQ,KACJ,uRAII,EAAA,qBACR,GACJ"}