{"record":{"id":"414e8ba98f5caf18","repo":"ianstormtaylor/slate","slug":"the-selection-hyperscript-tag-must-have-a-focus","errorCode":null,"errorMessage":"The <selection> hyperscript tag must have a <focus> tag as a child with `path` and `offset` attributes defined.","messagePattern":"The <selection> hyperscript tag must have a <focus> 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":171,"sourceCode":" * 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,\n    },\n    ...attributes,\n  }\n}\n\n/**","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate-hyperscript/src/creators.ts#L153-L189","documentation":"Thrown by the <selection> hyperscript tag when no <focus> child with both path and offset attributes was found. A Slate range needs both anchor and focus; hyperscript validates the focus point was fully specified.","triggerScenarios":"Writing <selection><anchor path={[0,0]} offset={0} /></selection> without a <focus/>, or a <focus/> missing path or offset.","commonSituations":"Test fixtures where only the anchor was written; forgetting that offset is required even for offset 0.","solutions":["Add <focus path={[...]} offset={n} /> inside <selection>","For collapsed selections use <cursor path={[...]} offset={n} /> instead of anchor/focus pairs"],"exampleFix":"// before\n<selection>\n  <anchor path={[0,0]} offset={0} />\n</selection>\n// after\n<selection>\n  <anchor path={[0,0]} offset={0} />\n  <focus path={[0,0]} offset={0} />\n</selection>","handlingStrategy":"validation","validationCode":"const hasFocus = children.some(c => c instanceof FocusToken && c.path != null && c.offset != null)\nif (!hasFocus) throw new Error('fixture missing <focus path offset> in <selection>')","typeGuard":"const isCompleteFocus = (f?: FocusToken): f is FocusToken =>\n  !!f && f.path != null && f.offset != null","tryCatchPattern":"null","preventionTips":["Always pair <anchor/> and <focus/> with both path and offset","Use <cursor/> for collapsed selections","Remember offset does not default to 0"],"tags":["slate","hyperscript","selection","fixture"],"backgroundTag":"hyperscript-selection-missing-focus","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}