{"record":{"id":"2cae31af4997fdab","repo":"toeverything/AFFiNE","slug":"errorcode-valuenotexists","errorCode":"ErrorCode.ValueNotExists","errorMessage":"Host is not ready to use, the `render` method should be called first","messagePattern":"Host is not ready to use, the `render` method should be called first","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/std/src/scope/std-scope.ts","lineNumber":98,"sourceCode":"  get command() {\n    return this.get(CommandManager);\n  }\n\n  get event() {\n    return this.get(UIEventDispatcher);\n  }\n\n  get get() {\n    return this.provider.get.bind(this.provider);\n  }\n\n  get getOptional() {\n    return this.provider.getOptional.bind(this.provider);\n  }\n\n  get host() {\n    if (!this._host) {\n      throw new BlockSuiteError(\n        ErrorCode.ValueNotExists,\n        'Host is not ready to use, the `render` method should be called first'\n      );\n    }\n\n    return this._host;\n  }\n\n  get range() {\n    return this.get(RangeManager);\n  }\n\n  get selection() {\n    return this.get(StoreSelectionExtension);\n  }\n\n  get view() {\n    return this.get(ViewStore);","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/std/src/scope/std-scope.ts#L80-L116","documentation":"Thrown by the `BlockStdScope.host` getter in std-scope.ts. The scope holds a private `_host` that is only assigned when the `EditorHost` is mounted and `render()` has executed. Accessing `std.host` before that assignment triggers this `ValueNotExists` error — the host element does not yet exist.","triggerScenarios":"Calling `std.host`, `std.view`, or any API that routes through `host` (e.g. `blockComponent.host`, `renderChildren`, range/sync helpers) before `EditorHost` has rendered — typically inside a `BlockService.created()` hook, an `EditorLifeCycleExtension`, or a watcher's `created()` that runs during `BlockStdScope` construction.","commonSituations":"Service/watcher code that touches `std.host` synchronously in `created()` instead of waiting for the `mounted`/`rendered` lifecycle; using `std.host` in a constructor; a watcher that runs before the host has connected to the DOM.","solutions":["Move host-dependent code out of `created()` into the `rendered()` / `mounted()` lifecycle hook of the watcher or service.","Guard with `if (this.std.host)` or use an optional accessor before invoking host APIs.","Defer with `hostUpdated()` / `firstUpdated()` for Lit components.","Use the `EditorLifeCycleExtension` hooks (`created`, `rendered`, `disposed`) in the correct order."],"exampleFix":"// before: touching host in created() — runs before render\ncreated() { this.std.host.addEventListener('keydown', this.onKey); }\n\n// after: defer to the rendered() hook — host is assigned by then\nrendered() { this.std.host.addEventListener('keydown', this.onKey); }\ndisposed() { this.std.host?.removeEventListener('keydown', this.onKey); }","handlingStrategy":"validation","validationCode":"// guard host access in watchers/services\nfunction getHostSafe(std: BlockStdScope): EditorHost | null {\n  // `_host` is private; rely on a safe proxy if exposed, else check via try/catch\n  try {\n    return std.host;\n  } catch {\n    return null;\n  }\n}\n\nconst host = getHostSafe(this.std);\nif (host) host.addEventListener('keydown', this.onKey);","typeGuard":"import type { BlockStdScope } from '@blocksuite/std';\nimport type { EditorHost } from '@blocksuite/std/view';\n\nfunction stdHasHost(std: BlockStdScope): std is BlockStdScope & { host: EditorHost } {\n  try {\n    return !!std.host;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';\n\nlet host: EditorHost;\ntry {\n  host = this.std.host;\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.ValueNotExists) {\n    // not mounted yet; defer to the rendered() hook\n    return;\n  }\n  throw e;\n}","preventionTips":["Touch `std.host` only in `rendered()`/`mounted()` lifecycle hooks, never in `created()`.","Use optional chaining and null checks before host APIs.","Prefer `firstUpdated`/`hostUpdated` for Lit components."],"tags":["lifecycle","std-scope","editor-host","ordering"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}