{"record":{"id":"a96f8ede8ffebfe0","repo":"mihomo-party-org/clash-party","slug":"useprofileconfig-must-be-used-within-a-profileconf","errorCode":null,"errorMessage":"useProfileConfig must be used within a ProfileConfigProvider","messagePattern":"useProfileConfig must be used within a ProfileConfigProvider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/src/hooks/use-profile-config.tsx","lineNumber":151,"sourceCode":"      value={{\n        profileConfig: config,\n        setProfileConfig,\n        mutateProfileConfig: mutate,\n        addProfileItem,\n        removeProfileItem,\n        updateProfileItem,\n        changeCurrentProfile\n      }}\n    >\n      {children}\n    </ProfileConfigContext.Provider>\n  )\n}\n\nexport const useProfileConfig = (): ProfileConfigContextType => {\n  const context = React.useContext(ProfileConfigContext)\n  if (!context) {\n    throw new Error('useProfileConfig must be used within a ProfileConfigProvider')\n  }\n  return context\n}\n","sourceCodeStart":133,"sourceCodeEnd":155,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/renderer/src/hooks/use-profile-config.tsx#L133-L155","documentation":"useProfileConfig reads the ProfileConfig context and throws when it is called without a ProfileConfigProvider ancestor. Since the context has no meaningful default, undefined indicates the hook is being used outside its intended provider scope and the library fails fast with an explicit message.","triggerScenarios":"A component consuming useProfileConfig() is rendered outside <ProfileConfigProvider>; the provider is mounted conditionally or lower in the tree than the consumer; the hook is invoked from a separate React root (tests, modals mounted in another root).","commonSituations":"New screens added under a different route that bypasses the provider; provider accidentally removed during refactor; Storybook/test harness missing the wrapper; React 18 concurrent roots rendering parts of the UI independently.","solutions":["Place <ProfileConfigProvider> at the highest common ancestor of all components that call useProfileConfig.","Check the component tree (React DevTools) to confirm the provider actually wraps the throwing component.","Wrap test/storybook renders with ProfileConfigProvider.","If profiles may be absent, render the consumer only after the provider has mounted."],"exampleFix":"// before\n<Router>\n  <Route path=\"/profiles\" element={<ProfileSettings />} />\n</Router>\n// after\n<ProfileConfigProvider>\n  <Router>\n    <Route path=\"/profiles\" element={<ProfileSettings />} />\n  </Router>\n</ProfileConfigProvider>","handlingStrategy":"validation","validationCode":"const context = React.useContext(ProfileConfigContext)\nif (!context) {\n  return <ProfileConfigUnavailable />\n}","typeGuard":"function hasProfileConfig(c: ProfileConfigContextType | null | undefined): c is ProfileConfigContextType {\n  return c != null\n}","tryCatchPattern":null,"preventionTips":["Place ProfileConfigProvider at a single high-level location (app root) instead of per-route.","When moving components between routes, re-check provider ancestry in DevTools.","Add provider wrappers to test/Storybook harnesses and keep them in sync with the app tree.","Avoid rendering config consumers before the provider's data initialization completes; let the provider own loading state."],"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"}