{"record":{"id":"4fc07a96e9a4f781","repo":"ianstormtaylor/slate","slug":"cannot-set-the-then-property-of-the-selection-to","errorCode":null,"errorMessage":"Cannot set the \"then\" property of the selection to a function","messagePattern":"Cannot set the \"then\" property of the selection to a function","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/transforms/general.ts","lineNumber":328,"sourceCode":"        }\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          }\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","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/transforms/general.ts#L310-L346","documentation":"Slate refuses to set a 'then' property on the selection when the value is a function, because a thenable selection would be treated as a Promise-like object. Returning such a selection from an async function would auto-await it and cause surprising behavior, so Slate guards against it explicitly.","triggerScenarios":"Transforms.setSelection(editor, { then: () => {} }) or applying a set_selection op whose properties include then: function; usually from deserialized/untrusted data where 'then' is a function value.","commonSituations":"Applying remote or localStorage-persisted operations that were not sanitized; JSON payloads where a key named 'then' resolved to a function via eval-like revival; prototype-pollution attempts.","solutions":["Strip any 'then' key from selection properties before calling setSelection","Validate that no property value in the operation is a function before applying remote ops","If you need a custom selection key, rename it away from 'then'"],"exampleFix":"// before\nTransforms.setSelection(editor, propsWithThen as any)\n\n// after\ndelete propsWithThen['then']\nTransforms.setSelection(editor, propsWithThen as Partial<Range>)","handlingStrategy":"validation","validationCode":"if ('then' in props && typeof props['then'] === 'function') {\n  throw new Error('then must not be a function on selection')\n}\nconst { then, ...rest } = props as any\nTransforms.setSelection(editor, rest)","typeGuard":"const hasFunctionThen = (o: object): boolean =>\n  'then' in o && typeof (o as any).then === 'function'","tryCatchPattern":null,"preventionTips":["Never assign 'then' on selection objects","Strip 'then' when deserializing/reviving remote data","Reject ops containing function-valued properties"],"tags":["selection","promise","thenable","security","slate"],"backgroundTag":"forbidden-property-assignment","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}