{"record":{"id":"b461f1d18b6931d4","repo":"ianstormtaylor/slate","slug":"cannot-set-the-then-property-of-a-node-to-a-func","errorCode":null,"errorMessage":"Cannot set the \"then\" property of a node to a function","messagePattern":"Cannot set the \"then\" property of a node to a function","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/transforms/general.ts","lineNumber":266,"sourceCode":"          throw new Error(`Cannot set properties on the root node!`)\n        }\n\n        modifyDescendant(editor, path, node => {\n          const newNode = { ...node }\n\n          for (const key in newProperties) {\n            if (NON_SETTABLE_NODE_PROPERTIES.includes(key)) {\n              throw new Error(`Cannot set the \"${key}\" property of nodes!`)\n            }\n\n            const value = newProperties[<keyof Node>key]\n\n            // Make sure we're not setting `then` to a function, since this will\n            // cause the node to be treated as a Promise-like object, which can\n            // cause unexpected behaviour when returning the node from async\n            // functions.\n            if (key === 'then' && typeof value === 'function') {\n              throw new Error(\n                'Cannot set the \"then\" property of a node to a function'\n              )\n            }\n\n            if (value == null) {\n              delete newNode[<keyof Node>key]\n            } else {\n              newNode[<keyof Node>key] = value\n            }\n          }\n\n          // properties that were previously defined, but are now missing, must be deleted\n          for (const key in properties) {\n            if (!Object.hasOwn(newProperties, key)) {\n              delete newNode[<keyof Node>key]\n            }\n          }\n","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/transforms/general.ts#L248-L284","documentation":"Slate refuses to set a node's 'then' property to a function. A thenable node would be treated as a Promise-like object, breaking await behavior, React Suspense, and serialization when nodes are returned from async code.","triggerScenarios":"Applying set_node where newProperties.then is a function — typically accidental, e.g. spreading an object containing a then callback into Transforms.setNodes props, or deserializing untrusted JSON into node properties.","commonSituations":"Spreading arbitrary/foreign objects into node properties; accepting node JSON from untrusted input; test fixtures accidentally including a then function.","solutions":["Whitelist the keys you set: only copy known-safe property keys instead of spreading whole objects into setNodes.","Strip 'then' (and any function-valued keys) from deserialized properties before applying.","If you genuinely need a then field, store it as a non-function value or under a different key."],"exampleFix":"// before\nTransforms.setNodes(editor, props, { at: path }) // props may contain then\n\n// after\nconst safe = Object.fromEntries(\n  Object.entries(props).filter(\n    ([k, v]) => k !== 'then' && typeof v !== 'function'\n  )\n)\nTransforms.setNodes(editor, safe, { at: path })","handlingStrategy":"validation","validationCode":"const safe = Object.fromEntries(\n  Object.entries(props).filter(\n    ([k, v]) => k !== 'then' && typeof v !== 'function'\n  )\n)\nTransforms.setNodes(editor, safe, { at: path })","typeGuard":"function hasNoThenFunction(props: Record<string, unknown>): boolean {\n  return !('then' in props) || typeof props.then !== 'function'\n}","tryCatchPattern":null,"preventionTips":["Strip 'then' and function-valued keys from deserialized node properties.","Whitelist known-safe keys when setting node props from external data.","Never spread arbitrary objects into setNodes."],"tags":["slate","set-node","thenable","prototype-pollution"],"backgroundTag":"operation-validation-failed","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}