{"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/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/framework/std/src/scope/std-scope.ts#L80-L116","documentation":"BlockStdScope.host throws ErrorCode.ValueNotExists until std.render() has been called, because render() is what creates the EditorHost element and assigns this._host (std-scope.ts:152-162). Any code reaching for std.host before that point — e.g. inside the created() lifecycle hook, a service constructor, or a standalone std used for headless work — hits this error. It is an initialization-order guard, not corruption.","triggerScenarios":"Accessing std.host (directly or via helpers that use it) inside a LifeCycleWatcher's created() hook, an extension's setup/constructor, or before appending the editor to the DOM; building a BlockStdScope for headless operations (snapshot/job work) and touching UI-only APIs.","commonSituations":"Custom extensions or commands that grab std.host at construction time instead of in mounted()/rendered(); using @blocksuite/std programmatically without the <editor-container> wrapper; upgrading BlockSuite versions where older code accessed host earlier than the new lifecycle allows.","solutions":["Call and use the result of std.render() (or mount the standard editor container, which does it for you) before touching std.host.","Move host-dependent logic into the rendered()/mounted() lifecycle hooks of an EditorLifeCycleExtension/LifeCycleWatcher.","For headless/store-only work, use the Store API directly instead of std.host.","Guard with getOptional-style checks or 'host' in try/catch when std may be unrendered."],"exampleFix":"// before\nclass MyWatcher extends LifeCycleWatcher {\n  created() { this.std.host.addEventListener('keydown', ...); }\n}\n\n// after\ncreated() { /* no DOM yet */ }\nrendered() { this.std.host.addEventListener('keydown', ...); }","handlingStrategy":"validation","validationCode":"// Before touching std.host, ensure render happened:\nconst host = std.render(); // idempotent pattern: call render once, reuse element\nif (!host.isConnected) document.body.append(host);","typeGuard":null,"tryCatchPattern":"import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';\ntry {\n  std.host.focus();\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.ValueNotExists) {\n    // not rendered yet — schedule for after render\n  } else throw e;\n}","preventionTips":["Only access std.host in rendered()/mounted() lifecycle hooks, never in created()/constructors.","Mount editors through the standard editor container, which calls render() for you.","Use the Store API directly for headless/snapshot work instead of std.host."],"tags":["blocksuite","lifecycle","initialization-order","editor-host"],"backgroundTag":"access-before-initialization","analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}