{"record":{"id":"b8809e4c339d7887","repo":"ianstormtaylor/slate","slug":"the-selection-hyperscript-tag-must-have-an-anch","errorCode":null,"errorMessage":"The <selection> hyperscript tag must have an <anchor> tag as a child with `path` and `offset` attributes defined.","messagePattern":"The <selection> hyperscript tag must have an <anchor> tag as a child with `path` and `offset` attributes defined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate-hyperscript/src/creators.ts","lineNumber":165,"sourceCode":"  children: any[]\n): PointToken {\n  return new PointToken(attributes)\n}\n\n/**\n * Create a `Selection` object.\n */\n\nexport function createSelection(\n  tagName: string,\n  attributes: { [key: string]: any },\n  children: any[]\n): Range {\n  const anchor: AnchorToken = children.find(c => c instanceof AnchorToken)\n  const focus: FocusToken = children.find(c => c instanceof FocusToken)\n\n  if (!anchor || anchor.offset == null || anchor.path == null) {\n    throw new Error(\n      `The <selection> hyperscript tag must have an <anchor> tag as a child with \\`path\\` and \\`offset\\` attributes defined.`\n    )\n  }\n\n  if (!focus || focus.offset == null || focus.path == null) {\n    throw new Error(\n      `The <selection> hyperscript tag must have a <focus> tag as a child with \\`path\\` and \\`offset\\` attributes defined.`\n    )\n  }\n\n  return {\n    anchor: {\n      offset: anchor.offset,\n      path: anchor.path,\n    },\n    focus: {\n      offset: focus.offset,\n      path: focus.path,","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate-hyperscript/src/creators.ts#L147-L183","documentation":"Thrown by the <selection> hyperscript tag when no <anchor> child with both path and offset attributes was found. A Slate selection requires a defined anchor point, and hyperscript validates that anchor path/offset were provided.","triggerScenarios":"Writing <selection><focus path={[0,0]} offset={0} /></selection> without an <anchor/>, or an <anchor/> missing either the path or offset attribute.","commonSituations":"Building test fixtures with hyperscript and forgetting the anchor half of the selection, or omitting offset assuming it defaults to 0 (it does not).","solutions":["Add <anchor path={[...]} offset={n} /> inside <selection>","If you meant a collapsed selection, use a single <cursor /> tag with path/offset instead"],"exampleFix":"// before\n<selection>\n  <focus path={[0,0]} offset={0} />\n</selection>\n// after\n<selection>\n  <anchor path={[0,0]} offset={0} />\n  <focus path={[0,1]} offset={2} />\n</selection>","handlingStrategy":"validation","validationCode":"// fixture-level check before createSelection:\nconst hasAnchor = children.some(c => c instanceof AnchorToken && c.path != null && c.offset != null)\nif (!hasAnchor) throw new Error('fixture missing <anchor path offset> in <selection>')","typeGuard":"const isCompleteAnchor = (a?: AnchorToken): a is AnchorToken =>\n  !!a && a.path != null && a.offset != null","tryCatchPattern":"null","preventionTips":["Always pair <anchor/> and <focus/> with both path and offset in <selection>","Use <cursor/> for collapsed selections","Lint fixtures that build selections"],"tags":["slate","hyperscript","selection","fixture"],"backgroundTag":"hyperscript-selection-missing-anchor","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}