{"record":{"id":"5004abd0149f679b","repo":"toeverything/AFFiNE","slug":"component-must-be-created-in-the-context-of-a-prov","errorCode":null,"errorMessage":"Component must be created in the context of a provider","messagePattern":"Component must be created in the context of a provider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/infra/src/framework/core/components/component.ts","lineNumber":17,"sourceCode":"import { CONSTRUCTOR_CONTEXT } from '../constructor-context';\nimport type { FrameworkProvider } from '../provider';\n\nexport class Component<Props = {}> {\n  readonly framework: FrameworkProvider;\n\n  readonly props: Props;\n\n  protected readonly disposables: (() => void)[] = [];\n\n  get eventBus() {\n    return this.framework.eventBus;\n  }\n\n  constructor() {\n    if (!CONSTRUCTOR_CONTEXT.current.provider) {\n      throw new Error('Component must be created in the context of a provider');\n    }\n    this.framework = CONSTRUCTOR_CONTEXT.current.provider;\n    this.props = CONSTRUCTOR_CONTEXT.current.props;\n    CONSTRUCTOR_CONTEXT.current = {};\n  }\n\n  dispose() {\n    this.disposables.forEach(dispose => dispose());\n  }\n\n  [Symbol.dispose]() {\n    this.dispose();\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/infra/src/framework/core/components/component.ts#L1-L32","documentation":"Component's constructor reads the ambient CONSTRUCTOR_CONTEXT and throws when no provider is active, i.e. the component was instantiated with 'new' outside framework-managed creation (like a provider factory), which would leave it without DI services.","triggerScenarios":"Thrown at packages/common/infra/src/framework/core/components/component.ts:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create the component inside a provider context, e.g. within framework.run or a provider scope.","Do not instantiate components at module top level; defer creation until a provider is active.","Check the stack trace for the component created outside any provider and move it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}