{"record":{"id":"c16c32ffbeaff3b1","repo":"jeecgboot/JeecgBoot","slug":"usedrawerinner-can-only-be-used-inside-setup-o","errorCode":null,"errorMessage":"useDrawerInner() can only be used inside setup() or functional components!","messagePattern":"useDrawerInner\\(\\) can only be used inside setup\\(\\) or functional components!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"jeecgboot-vue3/src/components/Drawer/src/useDrawer.ts","lineNumber":97,"sourceCode":"        dataTransferRef[unref(uid)] = toRaw(data);\n      }\n    },\n    closeDrawer: () => {\n      // 代码逻辑说明: 【QQYUN-6366】升级到antd4.x\n      getInstance()?.setDrawerProps({ open: false });\n    },\n  };\n\n  return [register, methods];\n}\n\nexport const useDrawerInner = (callbackFn?: Fn): UseDrawerInnerReturnType => {\n  const drawerInstanceRef = ref<Nullable<DrawerInstance>>(null);\n  const currentInstance = getCurrentInstance();\n  const uidRef = ref<string>('');\n\n  if (!getCurrentInstance()) {\n    throw new Error('useDrawerInner() can only be used inside setup() or functional components!');\n  }\n\n  const getInstance = () => {\n    const instance = unref(drawerInstanceRef);\n    if (!instance) {\n      error('useDrawerInner instance is undefined!');\n      return;\n    }\n    return instance;\n  };\n\n  const register = (modalInstance: DrawerInstance, uuid: string) => {\n    isProdMode() &&\n      tryOnUnmounted(() => {\n        drawerInstanceRef.value = null;\n      });\n\n    uidRef.value = uuid;","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecgboot-vue3/src/components/Drawer/src/useDrawer.ts#L79-L115","documentation":"useDrawerInner is the inner-side hook used by the component rendered inside a Drawer (it receives data transferred from the opener and accesses the drawer instance). It captures getCurrentInstance() into a variable and also re-checks it in the guard. Like useDrawer, it requires a setup context because it registers lifecycle cleanup. The double getCurrentInstance() call is redundant but harmless. It throws the same class of message when no instance is present.","triggerScenarios":"Calling useDrawerInner() in a non-component module, a Pinia store, a composable invoked outside setup, or any detached async context. Because the inner component is usually a child route/view, a common trigger is the child view failing to be a real Vue component (e.g. a plain function returning JSX without defineComponent).","commonSituations":"Refactoring the inner drawer view into a separate file but calling the hook in a utility; using useDrawerInner inside a render function without a proper component definition; calling it during SSR where instance availability differs.","solutions":["Call useDrawerInner() at the top of the inner component's <script setup>.","Ensure the inner drawer content is defined as a proper Vue component (defineComponent or <script setup>).","Do not call useDrawerInner from the parent/opener component — it belongs only in the inner view.","If using a callback function parameter, ensure it does not itself call the hook; pass it as an argument instead."],"exampleFix":"// before — inner logic placed in a helper file\n// drawerHelper.ts\nexport function setupDrawer() {\n  const [register] = useDrawerInner(cb); // throws\n}\n\n// after — move into the actual inner .vue component\n// InnerDrawer.vue <script setup>\nconst [register] = useDrawerInner((data) => { /* ... */ });","handlingStrategy":"validation","validationCode":"import { getCurrentInstance } from 'vue';\nfunction safeUseDrawerInner(cb?: Fn) {\n  if (!getCurrentInstance()) {\n    console.error('useDrawerInner must be called inside the inner drawer component setup');\n    return null;\n  }\n  return useDrawerInner(cb);\n}","typeGuard":"import { getCurrentInstance } from 'vue';\nconst canUseLifecycle = () => !!getCurrentInstance();","tryCatchPattern":"try {\n  const [register] = useDrawerInner(cb);\n} catch (e) {\n  // move the call into the inner .vue component's setup\n}","preventionTips":["Reserve useDrawerInner for the component rendered inside the Drawer only.","Ensure inner content is a real defineComponent/<script setup>.","Do not forward the callback into a detached async context."],"tags":["vue3","composition-api","drawer","setup","lifecycle"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}