{"record":{"id":"d1f4b88d119ac7ba","repo":"toeverything/AFFiNE","slug":"invalid-element-type-ymap-get-type","errorCode":null,"errorMessage":"Invalid element type: ${yMap.get('type')}","messagePattern":"Invalid element type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/std/src/gfx/model/surface/surface-model.ts","lineNumber":247,"sourceCode":"    type: string,\n    id: string,\n    yMap: Y.Map<unknown>,\n    options: {\n      onChange: (payload: {\n        id: string;\n        props: Record<string, unknown>;\n        oldValues: Record<string, unknown>;\n        local: boolean;\n      }) => void;\n      skipFieldInit?: boolean;\n      newCreate?: boolean;\n    }\n  ) {\n    const stashed = new Map<string | symbol, unknown>();\n    const Ctor = this._elementCtorMap[type];\n\n    if (!Ctor) {\n      throw new Error(`Invalid element type: ${yMap.get('type')}`);\n    }\n    const state = this._decoratorState;\n\n    state.creating = true;\n    state.skipField = options.skipFieldInit ?? false;\n\n    let mounted = false;\n    // @ts-expect-error ignore\n    Ctor['_decoratorState'] = state;\n\n    const elementModel = new Ctor({\n      id,\n      yMap,\n      model: this,\n      stashedStore: stashed,\n      onChange: payload => mounted && options.onChange({ id, ...payload }),\n    }) as GfxPrimitiveElementModel;\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/framework/std/src/gfx/model/surface/surface-model.ts#L229-L265","documentation":"_createElementFromYMap looks up the constructor registered for a surface element's 'type' read from Yjs and throws when no such element type is registered, usually caused by deserializing data written by a newer/different build with unregistered element types.","triggerScenarios":"Thrown at blocksuite/framework/std/src/gfx/model/surface/surface-model.ts:247 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the 'type' field stored in the Y.Map — it must be one of the registered surface element types (shape, text, connector, group, brush, etc.).","Register the missing element type's schema/converter before deserializing the surface model.","If the document was created by a newer/older version, run a migration or ignore unknown element types instead of throwing."],"exampleFix":"const type = yMap.get('type');\nif (!elementConverters[type]) {\n  console.warn(`Skipping unknown surface element type: ${type}`);\n  return null; // or register the converter before loading\n}","handlingStrategy":"type-guard","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-14T05:17:10.506Z"}