{"record":{"id":"bbc453eaba5c9254","repo":"mihomo-party-org/clash-party","slug":"useoverrideconfig-must-be-used-within-an-overridec","errorCode":null,"errorMessage":"useOverrideConfig must be used within an OverrideConfigProvider","messagePattern":"useOverrideConfig must be used within an OverrideConfigProvider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/src/hooks/use-override-config.tsx","lineNumber":97,"sourceCode":"    <OverrideConfigContext.Provider\n      value={{\n        overrideConfig: config,\n        setOverrideConfig,\n        mutateOverrideConfig: mutate,\n        addOverrideItem,\n        removeOverrideItem,\n        updateOverrideItem\n      }}\n    >\n      {children}\n    </OverrideConfigContext.Provider>\n  )\n}\n\nexport const useOverrideConfig = (): OverrideConfigContextType => {\n  const context = React.useContext(OverrideConfigContext)\n  if (!context) {\n    throw new Error('useOverrideConfig must be used within an OverrideConfigProvider')\n  }\n  return context\n}\n","sourceCodeStart":79,"sourceCodeEnd":101,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/renderer/src/hooks/use-override-config.tsx#L79-L101","documentation":"useOverrideConfig consumes the OverrideConfig context and throws when the context value is falsy, i.e. when the hook runs without an OverrideConfigProvider above it in the React tree. The library throws to surface the misconfiguration immediately rather than allowing undefined config access later.","triggerScenarios":"Invoking useOverrideConfig() in a component rendered outside <OverrideConfigProvider>; using the hook before the provider mounts (e.g. in the same render pass as the provider is conditionally introduced); calling it from a second React root such as a test render or a popup window.","commonSituations":"Forgetting the provider when adding the hook to a new component; conditional provider mounting (provider rendered only after some state loads) while consumers render unconditionally; RTL/Storybook setups missing the wrapper.","solutions":["Mount <OverrideConfigProvider> around the whole app or at least around all consumers of useOverrideConfig.","Make provider mounting unconditional (keep it mounted; handle loading state inside it).","In tests/stories, wrap the render call with OverrideConfigProvider.","Add a lint/test assertion or an ErrorBoundary-friendly check that the provider exists in the tree."],"exampleFix":"// before\nrenderHook(() => useOverrideConfig())\n// after\nconst wrapper = ({ children }) => <OverrideConfigProvider>{children}</OverrideConfigProvider>\nrenderHook(() => useOverrideConfig(), { wrapper })","handlingStrategy":"validation","validationCode":"const context = React.useContext(OverrideConfigContext)\nif (!context) {\n  console.warn('OverrideConfigProvider missing — component will not render config-dependent UI')\n  return <ConfigUnavailable />\n}","typeGuard":"function hasOverrideConfig(c: OverrideConfigContextType | null | undefined): c is OverrideConfigContextType {\n  return Boolean(c)\n}","tryCatchPattern":null,"preventionTips":["Mount OverrideConfigProvider above the entire app root; avoid conditional provider rendering.","Use React DevTools to confirm the provider wraps any component calling useOverrideConfig.","Include the provider in Storybook decorators and RTL wrappers.","Run a smoke test that renders every route so missing-provider crashes surface in CI."],"tags":["react","context","hooks"],"backgroundTag":"react-context-used-outside-provider","analyzedSha":"911e090537acdf7c50bee1c3aebecc2ef119a8b5","analyzedAt":"2026-08-30T13:00:49.174Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}