{"record":{"id":"f2f0000dec01099d","repo":"twentyhq/twenty","slug":"unmountfrontcomponentfunction-is-not-set","errorCode":null,"errorMessage":"unmountFrontComponentFunction is not set","messagePattern":"unmountFrontComponentFunction is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-sdk/src/sdk/front-component/functions/unmountFrontComponent.ts","lineNumber":13,"sourceCode":"import { isDefined } from 'twenty-shared/utils';\n\nimport {\n  frontComponentHostCommunicationApi,\n  type UnmountFrontComponentFunction,\n} from '../globals/frontComponentHostCommunicationApi';\n\nexport const unmountFrontComponent: UnmountFrontComponentFunction = () => {\n  const unmountFrontComponentFunction =\n    frontComponentHostCommunicationApi.unmountFrontComponent;\n\n  if (!isDefined(unmountFrontComponentFunction)) {\n    throw new Error('unmountFrontComponentFunction is not set');\n  }\n\n  return unmountFrontComponentFunction();\n};\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-sdk/src/sdk/front-component/functions/unmountFrontComponent.ts#L1-L18","documentation":"Thrown by unmountFrontComponent when the host application has not registered an unmountFrontComponent function on the global frontComponentHostCommunicationApi. This function is the mechanism by which a front component asks the Twenty host shell to unmount/remove it. If called outside the host context, the function is undefined.","triggerScenarios":"Calling unmountFrontComponent() before the host has set frontComponentHostCommunicationApi.unmountFrontComponent. Occurs in non-host environments (standalone, test, SSR), when host bridge initialization failed, or when called prematurely before host mounting completes.","commonSituations":"Unit testing a component that calls unmountFrontComponent without mocking the global API. Running a front component in Storybook or a standalone preview. The host shell's bridge was not initialized due to a configuration error. Calling unmount during an error boundary's render phase before the host has set up the bridge.","solutions":["Only call unmountFrontComponent from within a component lifecycle (e.g. button click handler) that is running inside the Twenty host shell.","In tests, mock the global: (globalThis as any).frontComponentHostCommunicationApi = { unmountFrontComponent: jest.fn().mockResolvedValue(undefined) }.","Verify the host app sets frontComponentHostCommunicationApi.unmountFrontComponent before mounting front components.","Guard the call with an isDefined check on the function before invoking."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"import { frontComponentHostCommunicationApi } from 'twenty-sdk';\nimport { isDefined } from 'twenty-shared/utils';\n\nconst canUnmount = (): boolean => {\n  return isDefined(frontComponentHostCommunicationApi.unmountFrontComponent);\n};\n\nif (!canUnmount()) {\n  console.warn('unmountFrontComponent unavailable — not in host context.');\n  return;\n}","typeGuard":"import { isDefined } from 'twenty-shared/utils';\nimport { frontComponentHostCommunicationApi } from 'twenty-sdk';\n\nconst isUnmountAvailable = (): boolean => {\n  return isDefined(frontComponentHostCommunicationApi.unmountFrontComponent);\n};","tryCatchPattern":"try {\n  await unmountFrontComponent();\n} catch (error) {\n  if (error instanceof Error && error.message === 'unmountFrontComponentFunction is not set') {\n    console.warn('Unmount not available outside host context.');\n    return;\n  }\n  throw error;\n}","preventionTips":["Only call unmountFrontComponent from within host-mounted component lifecycle.","Mock frontComponentHostCommunicationApi.unmountFrontComponent in tests.","Guard with isDefined to no-op safely in non-host environments."],"tags":["sdk","front-component","host-bridge","global-state"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}