ianstormtaylor/slate · error · Error

Cannot set the "${key}" property of the selection!

Error message

Cannot set the "${key}" property of the selection!

What it means

Thrown when a 'set_selection' operation tries to set a property that Slate forbids on selections (NON_SETTABLE_SELECTION_PROPERTIES, e.g. 'weight' from custom properties or internal keys). Slate only allows a defined subset of Range properties to be set on the selection to avoid corrupting internal state or prototype pollution-style keys.

Source

Thrown at packages/slate/src/interfaces/transforms/general.ts:316

        if (editor.selection == null) {
          if (!(newProperties.anchor && newProperties.focus)) {
            throw new Error(
              `Cannot apply an incomplete "set_selection" operation properties ${Scrubber.stringify(
                newProperties
              )} when there is no current selection.`
            )
          }

          editor.selection = { ...(newProperties as Range) }
          break
        }

        const selection = { ...editor.selection }

        for (const key in newProperties) {
          if (NON_SETTABLE_SELECTION_PROPERTIES.includes(key)) {
            throw new Error(
              `Cannot set the "${key}" property of the selection!`
            )
          }

          const value = newProperties[<keyof Range>key]

          // Make sure we're not setting `then` to a function, since this will
          // cause the selection to be treated as a Promise-like object, which
          // can cause unexpected behaviour when returning the selection from
          // async functions.
          if (key === 'then' && typeof value === 'function') {
            throw new Error(
              'Cannot set the "then" property of the selection to a function'
            )
          }

          if (value == null) {
            if (key === 'anchor' || key === 'focus') {

View on GitHub (pinned to 72a37c701e)

Solutions

  1. Remove the disallowed key from the properties object passed to setSelection
  2. Whitelist selection properties: only pass anchor, focus, mark, and other legitimate Range extension keys
  3. Sanitize remote operation properties before applying them (strip keys in NON_SETTABLE_SELECTION_PROPERTIES)

Example fix

// before
Transforms.setSelection(editor, { focus: p, weight: 1 } as any)

// after
Transforms.setSelection(editor, { focus: p })
Defensive patterns

Strategy: validation

Validate before calling

const SETTABLE = new Set(['anchor','focus','mark']) // extend with your own
const safe: Partial<Range> = {}
for (const k in props) if (SETTABLE.has(k)) safe[k] = props[k]
Transforms.setSelection(editor, safe)

Type guard

const isSettableSelectionKey = (k: string) =>
  !NON_SETTABLE_SELECTION_PROPERTIES.includes(k) && k !== 'then'

Prevention

When it happens

Trigger: Transforms.setSelection(editor, { [forbiddenKey]: value }) where forbiddenKey is in NON_SETTABLE_SELECTION_PROPERTIES (e.g. 'weight', 'then'); applying a crafted or remote set_selection operation containing disallowed keys.

Common situations: Copying arbitrary custom keys onto selection in collaborative editors; untrusted/remote operation payloads being applied without sanitization; custom Range extensions colliding with reserved keys.

Related errors


AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27). Data as JSON: /api/errors/bd06ea7bbc9cebbd. Report an issue: GitHub.