{"record":{"id":"125abe0c3a7eb216","repo":"shadcn-ui/ui","slug":"usehistory-must-be-used-within-typesethistoryprovi","errorCode":null,"errorMessage":"useHistory must be used within TypesetHistoryProvider","messagePattern":"useHistory must be used within TypesetHistoryProvider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/v4/app/(app)/(typeset)/hooks/use-history.tsx","lineNumber":179,"sourceCode":"  const value = React.useMemo(\n    () => ({ canGoBack, canGoForward, goBack, goForward }),\n    [canGoBack, canGoForward, goBack, goForward]\n  )\n\n  return (\n    <HistoryContext value={value}>\n      <Suspense>\n        <ParamsSync onChange={onChange} />\n      </Suspense>\n      {children}\n    </HistoryContext>\n  )\n}\n\nexport function useHistory() {\n  const context = React.useContext(HistoryContext)\n  if (!context) {\n    throw new Error(\"useHistory must be used within TypesetHistoryProvider\")\n  }\n  return context\n}\n","sourceCodeStart":161,"sourceCodeEnd":183,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/apps/v4/app/(app)/(typeset)/hooks/use-history.tsx#L161-L183","documentation":"Typeset variant of [142]. `useHistory` reads `HistoryContext`; `TypesetHistoryProvider` mounts it together with a `<ParamsSync onChange={...}>` Suspense boundary. A consumer outside that provider gets undefined and throws, ensuring the params-history API is always present.","triggerScenarios":"A typeset component calling `useHistory()` rendered outside `<TypesetHistoryProvider>`, e.g. reusing a (create) history-aware component under the (typeset) route without the typeset provider, or after refactoring the typeset layout.","commonSituations":"Cross-route component reuse; layout refactor dropping the provider; isolated test renders.","solutions":["Mount `<TypesetHistoryProvider onChange={...}>` above every typeset subtree that calls `useHistory()`.","Import the provider/hook from the (typeset) module so the context identity matches.","Wrap tests in the provider plus a Suspense boundary."],"exampleFix":"// before\n<TypesetPanel />\n\n// after\nimport { TypesetHistoryProvider } from \"@/(app)/(typeset)/hooks/use-history\"\n<TypesetHistoryProvider onChange={syncParams}>\n  <TypesetPanel />\n</TypesetHistoryProvider>","handlingStrategy":"type-guard","validationCode":"render(<TypesetHistoryProvider onChange={() => {}}>{<TypesetPanel/>}</TypesetHistoryProvider>)","typeGuard":"import React from \"react\"\nimport { HistoryContext } from \"@/(app)/(typeset)/hooks/use-history\"\nconst hasTypesetHistory = () => React.useContext(HistoryContext) != null","tryCatchPattern":"try { useHistory() } catch (e) { if (e.message.includes(\"TypesetHistoryProvider\")) {/*remount (typeset) provider*/} throw e }","preventionTips":["Mount TypesetHistoryProvider (with Suspense + ParamsSync) at the (typeset) layout root.","Import from the (typeset) module to match context identity.","Add the provider to test decorators."],"tags":["react","context","hooks","shadcn-v4","typeset","history"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}