{"record":{"id":"57bd7daba9f48437","repo":"shadcn-ui/ui","slug":"uselocks-must-be-used-within-locksprovider-57bd7d","errorCode":null,"errorMessage":"useLocks must be used within LocksProvider","messagePattern":"useLocks must be used within LocksProvider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/v4/app/(app)/(typeset)/hooks/use-locks.tsx","lineNumber":50,"sourceCode":"      } else {\n        next.add(param)\n      }\n      return next\n    })\n  }, [])\n\n  const value = React.useMemo(\n    () => ({ locks, isLocked, toggleLock }),\n    [locks, isLocked, toggleLock]\n  )\n\n  return <LocksContext value={value}>{children}</LocksContext>\n}\n\nexport function useLocks() {\n  const context = React.useContext(LocksContext)\n  if (!context) {\n    throw new Error(\"useLocks must be used within LocksProvider\")\n  }\n  return context\n}\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/apps/v4/app/(app)/(typeset)/hooks/use-locks.tsx#L32-L54","documentation":"Typeset variant of [143]. `useLocks` reads `LocksContext`; the typeset provider memoizes `{ locks, isLocked, toggleLock }`. A consumer outside `<LocksProvider>` throws so the lock contract can't be partially absent.","triggerScenarios":"A typeset panel that calls `useLocks()` rendered without a `<LocksProvider>` ancestor; sharing a lock-aware panel across create/typeset without re-wrapping.","commonSituations":"Route layout changes; portal/dialog rendering; isolated tests.","solutions":["Wrap the typeset subtree in `<LocksProvider>`.","Import from the (typeset) use-locks module to match the context instance.","Decorate tests with the provider."],"exampleFix":"// before\n<TypesetLockablePanel />\n\n// after\n<LocksProvider>\n  <TypesetLockablePanel />\n</LocksProvider>","handlingStrategy":"type-guard","validationCode":"render(<LocksProvider>{<TypesetLockablePanel/>}</LocksProvider>) // (typeset) LocksProvider","typeGuard":"import React from \"react\"\nimport { LocksContext } from \"@/(app)/(typeset)/hooks/use-locks\"\nconst hasTypesetLocks = () => React.useContext(LocksContext) != null","tryCatchPattern":"try { useLocks() } catch (e) { if (e.message.includes(\"LocksProvider\")) {/*wrap subtree*/} throw e }","preventionTips":["Mount the (typeset) LocksProvider at the typeset layout root.","Import from the (typeset) module to match context identity.","Reuse test decorators across (create)/(typeset) by parameterizing the provider."],"tags":["react","context","hooks","shadcn-v4","typeset","locks"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}