{"record":{"id":"a166407e7bf07bfc","repo":"toeverything/AFFiNE","slug":"errorcode-norootmodelerror","errorCode":"ErrorCode.NoRootModelError","errorMessage":"This doc is missing root block. Please initialize the default block structure before connecting the editor to DOM.","messagePattern":"This doc is missing root block\\. Please initialize the default block structure before connecting the editor to DOM\\.","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"critical","filePath":"blocksuite/framework/std/src/view/lit-host.ts","lineNumber":131,"sourceCode":null,"sourceCodeStart":null,"sourceCodeEnd":null,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/std/src/view/lit-host.ts#L131","documentation":"FATAL error (`NoRootModelError`, code >= 10000) thrown by `EditorHost.connectedCallback` in lit-host.ts when `this.store.root` is falsy at the moment the host connects to the DOM. BlockSuite requires the doc to have an initialized root block before the editor mounts; otherwise it cannot render anything and aborts. Because it is fatal, the framework's `handleError` rethrows it wrapped.","triggerScenarios":"Appending `<editor-host>` to the DOM before the doc has a root block — e.g. creating a `DocCollection`/`Store` and immediately mounting without calling `doc.reset()` / `aw Rap` initialization, or mounting before an async `loadStep`/`doc.load(...)` has populated the root.","commonSituations":"Empty new doc not given a default root block; importing a snapshot whose root failed to deserialize; awaiting `doc.loaded` incorrectly; SSR pass with an uninitialized doc.","solutions":["Initialize the root block before mounting: `doc.reset()` or add a default root block via the doc API.","Await the doc's loaded signal/promise (`await doc.loaded` / `store.awarenessStore` ready) before connecting `<editor-host>`.","Verify the snapshot import produced a non-null `store.root` before mounting."],"exampleFix":"// before: mounting an uninitialized doc\nconst doc = collection.createDoc();\ndocument.body.appendChild(host); // store.root is null -> fatal\n\n// after: initialize the root block first, then mount\nconst doc = collection.createDoc();\ndoc.load();\ndoc.reset(); // creates the default root block structure\ndocument.body.appendChild(host);","handlingStrategy":"validation","validationCode":"// ensure the doc has a root before mounting the editor host\nfunction docHasRoot(store: Store): boolean {\n  return !!store.root;\n}\n\nif (docHasRoot(store)) document.body.appendChild(host);\nelse throw new Error('Initialize the root block before mounting the editor.');","typeGuard":"function storeHasRoot(store: Store): store is Store & { root: BlockModel } {\n  return !!store.root;\n}","tryCatchPattern":"// No recovery: this is fatal. Validate before mount instead.\nif (!store.root) {\n  throw new Error('Cannot mount editor without a root block');\n}\ntry {\n  document.body.appendChild(host);\n} catch (e) {\n  if (e instanceof Error && /missing root block/i.test(e.message)) {\n    console.error('Editor mount failed: doc has no root block');\n  }\n  throw e;\n}","preventionTips":["Call `doc.reset()` (or add a default root block) before appending `<editor-host>`.","Await `doc.loaded` before mounting.","Verify snapshot import yields a non-null `store.root`."],"tags":["editor-host","doc","root-block","fatal","lifecycle"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}