{"record":{"id":"ad30063cf3d132e6","repo":"TanStack/query","slug":"no-queryclient-was-found-in-svelte-context-did-yo","errorCode":null,"errorMessage":"No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?","messagePattern":"No QueryClient was found in Svelte context\\. Did you forget to wrap your component with QueryClientProvider\\?","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/svelte-query/src/context.ts","lineNumber":11,"sourceCode":"import { getContext, setContext } from 'svelte'\nimport type { QueryClient } from '@tanstack/query-core'\nimport type { Box } from './containers.svelte'\n\nconst _contextKey = Symbol('QueryClient')\n\n/** Retrieves a Client from Svelte's context */\nexport const getQueryClientContext = (): QueryClient => {\n  const client = getContext<QueryClient | undefined>(_contextKey)\n  if (!client) {\n    throw new Error(\n      'No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?',\n    )\n  }\n\n  return client\n}\n\n/** Sets a QueryClient on Svelte's context */\nexport const setQueryClientContext = (client: QueryClient): void => {\n  setContext(_contextKey, client)\n}\n\nconst _isRestoringContextKey = Symbol('isRestoring')\n\n/** Retrieves a `isRestoring` from Svelte's context */\nexport const getIsRestoringContext = (): Box<boolean> => {\n  try {\n    const isRestoring = getContext<Box<boolean> | undefined>(","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/TanStack/query/blob/159982c80b844487054155c38ffc760fe4208daf/packages/svelte-query/src/context.ts#L1-L29","documentation":"Thrown by `getQueryClientContext` in `@tanstack/svelte-query`. The function calls Svelte's `getContext` with the internal `QueryClient` symbol key; if no ancestor called `setQueryClientContext` (typically via `QueryClientProvider`), the context is undefined and the function refuses to return.","triggerScenarios":"Using any svelte-query hook (`createQuery`, `createMutation`, etc.) in a component rendered outside `<QueryClientProvider>`; calling a hook in a `.svelte.ts` module that runs outside the component tree; setting the client on a different context key; SSR where context was not propagated.","commonSituations":"Forgetting the provider in `App.svelte` or `+layout.svelte`; using svelte-query inside a non-component utility; providing the client only in a child route while hooks run in the parent; mixing `setQueryClientContext` with a custom key.","solutions":["Wrap the component tree with `<QueryClientProvider client={queryClient}>`.","Call `setQueryClientContext(queryClient)` in the root component's setup if not using the provider component.","Ensure hooks are called inside `.svelte` components or `.svelte.js/.svelte.ts` modules invoked from a component's reactive context.","For SSR, set the client in the root `+layout.svelte` and verify context propagation through slots."],"exampleFix":"// before\n// App.svelte\n<Counter />\n// after\n<script>import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'; const qc = new QueryClient();</script>\n<QueryClientProvider client={qc}><Counter /></QueryClientProvider>","handlingStrategy":"validation","validationCode":"import { getContext } from 'svelte'\nimport { QueryClient } from '@tanstack/query-core'\nconst QUERY_CLIENT_KEY = Symbol('QueryClient')\nfunction peekQueryClient(): QueryClient | undefined {\n  return getContext<QueryClient | undefined>(QUERY_CLIENT_KEY)\n}","typeGuard":"const isQueryClient = (v: unknown): v is QueryClient =>\n  !!v && typeof (v as QueryClient).getQueryCache === 'function'","tryCatchPattern":null,"preventionTips":["Always wrap the root component tree with `<QueryClientProvider>`.","Set context via `setQueryClientContext(qc)` in `+layout.svelte` for SvelteKit.","Keep all svelte-query hook calls inside `.svelte` or `.svelte.ts` modules run from the component tree.","For SSR, set the client in the root layout and verify propagation."],"tags":["svelte","context","queryclient","configuration"],"backgroundTag":null,"analyzedSha":"159982c80b844487054155c38ffc760fe4208daf","analyzedAt":"2026-08-12T16:21:52.822Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}