{"record":{"id":"12fd72db88809212","repo":"ianstormtaylor/slate","slug":"cannot-apply-an-incomplete-set-selection-operati","errorCode":null,"errorMessage":"Cannot apply an incomplete \"set_selection\" operation properties ${Scrubber.stringify(\n                newProperties\n              )} when there is no current selection.","messagePattern":"Cannot apply an incomplete \"set_selection\" operation properties (.+?) when there is no current selection\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/transforms/general.ts","lineNumber":301,"sourceCode":"          }\n\n          return newNode\n        })\n\n        break\n      }\n\n      case 'set_selection': {\n        const { newProperties } = op\n\n        if (newProperties == null) {\n          editor.selection = null\n          break\n        }\n\n        if (editor.selection == null) {\n          if (!(newProperties.anchor && newProperties.focus)) {\n            throw new Error(\n              `Cannot apply an incomplete \"set_selection\" operation properties ${Scrubber.stringify(\n                newProperties\n              )} when there is no current selection.`\n            )\n          }\n\n          editor.selection = { ...(newProperties as Range) }\n          break\n        }\n\n        const selection = { ...editor.selection }\n\n        for (const key in newProperties) {\n          if (NON_SETTABLE_SELECTION_PROPERTIES.includes(key)) {\n            throw new Error(\n              `Cannot set the \"${key}\" property of the selection!`\n            )\n          }","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/transforms/general.ts#L283-L319","documentation":"Thrown by Editor.transform when applying a 'set_selection' operation with partial properties (missing anchor or focus) while editor.selection is null. Since there is no existing selection to merge the partial properties into, Slate cannot construct a valid new selection. It indicates the caller tried to update a selection that does not exist yet.","triggerScenarios":"Calling Transforms.setSelection(editor, {focus: ...}) or Editor.applySelection/Transforms.transform with partial range properties when editor.selection === null; replaying an operation log where a set_selection op assumes a prior selection existed.","commonSituations":"After deselect() or on a fresh editor with no selection, code applies remote/collaborative ops or calls setSelection with only anchor or only focus; desynced selection state in Yjs/ot-based collaboration.","solutions":["Check editor.selection != null before calling Transforms.setSelection with partial properties, or pass a full Range {anchor, focus}","If selection is null, use Transforms.select(editor, range) with a complete Range/Point/Path instead","When replaying remote operations, skip or re-order set_selection ops so a selection exists first"],"exampleFix":"// before\nTransforms.setSelection(editor, { focus: { path: [0,0], offset: 2 } }) // selection is null\n\n// after\nif (editor.selection) {\n  Transforms.setSelection(editor, { focus: { path: [0,0], offset: 2 } })\n} else {\n  Transforms.select(editor, { anchor: { path: [0,0], offset: 0 }, focus: { path: [0,0], offset: 2 } })\n}","handlingStrategy":"validation","validationCode":"const canSetSelection = editor.selection != null || (props.anchor != null && props.focus != null)\nif (!canSetSelection) throw new Error('Need full anchor+focus when selection is null')\nif (editor.selection != null) Transforms.setSelection(editor, props)\nelse Transforms.select(editor, props as Range)","typeGuard":"const isFullRange = (r: unknown): r is Range =>\n  Range.isRange(r) ||\n  (!!r && typeof r === 'object' && 'anchor' in r && 'focus' in r)","tryCatchPattern":null,"preventionTips":["Always provide both anchor and focus when editor.selection may be null","Check editor.selection before partial setSelection calls","When replaying ops, ensure a set_selection establishing a selection comes before partial updates"],"tags":["selection","operation","slate","validation"],"backgroundTag":"invalid-selection-state","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}