{"record":{"id":"720d3072040c9de6","repo":"ianstormtaylor/slate","slug":"cannot-remove-the-key-selection-property","errorCode":null,"errorMessage":"Cannot remove the \"${key}\" selection property","messagePattern":"Cannot remove the \"(.+?)\" selection property","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/transforms/general.ts","lineNumber":335,"sourceCode":"              `Cannot set the \"${key}\" property of the selection!`\n            )\n          }\n\n          const value = newProperties[<keyof Range>key]\n\n          // Make sure we're not setting `then` to a function, since this will\n          // cause the selection to be treated as a Promise-like object, which\n          // can cause unexpected behaviour when returning the selection from\n          // async functions.\n          if (key === 'then' && typeof value === 'function') {\n            throw new Error(\n              'Cannot set the \"then\" property of the selection to a function'\n            )\n          }\n\n          if (value == null) {\n            if (key === 'anchor' || key === 'focus') {\n              throw new Error(`Cannot remove the \"${key}\" selection property`)\n            }\n\n            delete selection[<keyof Range>key]\n          } else {\n            selection[<keyof Range>key] = value\n          }\n        }\n\n        editor.selection = selection\n\n        break\n      }\n\n      case 'split_node': {\n        const { path, position, properties } = op\n        const index = path[path.length - 1]\n\n        if (path.length === 0) {","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/transforms/general.ts#L317-L353","documentation":"Thrown when a set_selection operation tries to remove the anchor or focus property by setting it to null/undefined. A Slate selection cannot exist without anchor and focus points, so removing either is invalid.","triggerScenarios":"Transforms.setSelection(editor, { anchor: null }) or { focus: undefined }; remote ops setting anchor/focus to null; passing a partial object built from spread of an object with nullish anchor/focus.","commonSituations":"Merging optional props that can be undefined into selection updates; collaborative op replay where a peer cleared a point; incorrect construction like {...(cond && {anchor})} producing explicit undefined keys.","solutions":["Use editor.select(null) / Transforms.deselect(editor) to clear the whole selection instead of nulling anchor/focus","Filter out null/undefined anchor and focus before calling setSelection","Ensure the properties object only contains keys you intend to change with non-null point values"],"exampleFix":"// before\nTransforms.setSelection(editor, { focus: maybePoint }) // maybePoint may be undefined\n\n// after\nif (maybePoint) {\n  Transforms.setSelection(editor, { focus: maybePoint })\n} else {\n  Transforms.deselect(editor)\n}","handlingStrategy":"validation","validationCode":"const clean = Object.fromEntries(\n  Object.entries(props).filter(\n    ([k, v]) => !(v == null && (k === 'anchor' || k === 'focus'))\n  )\n)\nif (clean.anchor == null && clean.focus == null && Object.keys(clean).length === 0) {\n  Transforms.deselect(editor)\n} else {\n  Transforms.setSelection(editor, clean)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Transforms.deselect to clear a selection; never null out anchor/focus","Avoid conditional spreads that create explicit undefined keys","Validate point values are non-null before building selection updates"],"tags":["selection","null-property","slate","validation"],"backgroundTag":"invalid-selection-state","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}