{"record":{"id":"81387a8e2f849726","repo":"mantinedev/mantine","slug":"mantine-core-mantineprovider-was-not-found-in-t-81387a","errorCode":null,"errorMessage":"[@mantine/core] MantineProvider was not found in tree","messagePattern":"\\[@mantine/core\\] MantineProvider was not found in tree","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@mantine/core/src/core/MantineProvider/use-mantine-color-scheme/use-mantine-color-scheme.ts","lineNumber":30,"sourceCode":"  nonce && style.setAttribute('nonce', nonce);\n\n  document.head.appendChild(style);\n  const clear = () =>\n    document\n      .querySelectorAll('[data-mantine-disable-transition]')\n      .forEach((element) => element.remove());\n  return clear;\n}\n\nexport function useMantineColorScheme({ keepTransitions }: { keepTransitions?: boolean } = {}) {\n  const clearStylesRef = useRef<() => void>(noop);\n  const timeoutRef = useRef<number>(-1);\n  const ctx = use(MantineContext);\n  const nonce = useMantineStyleNonce();\n  const nonceValue = useRef(nonce?.());\n\n  if (!ctx) {\n    throw new Error('[@mantine/core] MantineProvider was not found in tree');\n  }\n\n  const setColorScheme = (value: MantineColorScheme) => {\n    ctx.setColorScheme(value);\n    clearStylesRef.current = keepTransitions ? () => {} : disableTransition(nonceValue.current);\n    window.clearTimeout(timeoutRef.current);\n    timeoutRef.current = window.setTimeout(() => {\n      clearStylesRef.current?.();\n    }, 10);\n  };\n\n  const clearColorScheme = () => {\n    ctx.clearColorScheme();\n    clearStylesRef.current = keepTransitions ? () => {} : disableTransition(nonceValue.current);\n    window.clearTimeout(timeoutRef.current);\n    timeoutRef.current = window.setTimeout(() => {\n      clearStylesRef.current?.();\n    }, 10);","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/mantinedev/mantine/blob/8a284e2c2c53a9cb6f39f5dc389bf41b7a2073f8/packages/@mantine/core/src/core/MantineProvider/use-mantine-color-scheme/use-mantine-color-scheme.ts#L12-L48","documentation":"useMantineColorScheme reads the color-scheme context created by MantineProvider. Calling it in a component rendered outside <MantineProvider> throws this error. Unlike useMantineContext, this hook also touches window/localStorage, but the throw here is purely the missing provider.","triggerScenarios":"Calling useMantineColorScheme() in a component above/outside MantineProvider (e.g. in the provider's own parent, a layout, or a second React root); unit tests without the provider wrapper.","commonSituations":"App shells where the theme toggle button lives outside the provider subtree; Next.js layout structure putting the provider in a child layout; RTL/Jest tests without a wrapper; micro-frontends with isolated roots.","solutions":["Move MantineProvider to the true root of the tree so every consumer (including the toggle) is a descendant","In tests, wrap with a custom render helper that includes MantineProvider","Restructure Next.js apps so the provider wraps the layout that contains the consumer"],"exampleFix":"// before\nexport function Layout({ children }) {\n  return (\n    <>\n      <ThemeToggle /> {/* uses useMantineColorScheme, throws */}\n      <MantineProvider>{children}</MantineProvider>\n    </>\n  );\n}\n\n// after\nexport function Layout({ children }) {\n  return (\n    <MantineProvider>\n      <ThemeToggle />\n      {children}\n    </MantineProvider>\n  );\n}","handlingStrategy":"validation","validationCode":"// Verify provider presence before render in dev\nif (!document.querySelector('[data-mantine-provider]')) {\n  console.warn('MantineProvider missing — wrap the app root');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Put MantineProvider above every component that touches color scheme, including theme toggles","Use a single renderWithProviders helper in tests","In Next.js, place the provider in the root layout"],"tags":["color-scheme","context","mantineprovider","react"],"backgroundTag":"missing-context-provider","analyzedSha":"8a284e2c2c53a9cb6f39f5dc389bf41b7a2073f8","analyzedAt":"2026-08-28T10:25:51.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}