ianstormtaylor/slate · error · Error
When setting the selection and the current selection is \`nu
Error message
When setting the selection and the current selection is \`null\` you must provide at least an \`anchor\` and \`focus\`, but you passed: ${Scrubber.stringify(
target
)} What it means
select() (Transforms.select) requires a full Range when the current editor selection is null, because there is nothing to derive the missing bound from. The target must be a complete Range with both anchor and focus (or a Point/Path which converts to one); a partial object like {anchor} alone is rejected.
Source
Thrown at packages/slate/src/transforms-selection/select.ts:17
import { SelectionTransforms } from '../interfaces/transforms/selection'
import { Editor } from '../interfaces/editor'
import { Transforms } from '../interfaces/transforms'
import { Scrubber } from '../interfaces/scrubber'
import { Location } from '../interfaces'
export const select: SelectionTransforms['select'] = (editor, target) => {
const { selection } = editor
target = Editor.range(editor, target)
if (selection) {
Transforms.setSelection(editor, target)
return
}
if (!Location.isRange(target)) {
throw new Error(
`When setting the selection and the current selection is \`null\` you must provide at least an \`anchor\` and \`focus\`, but you passed: ${Scrubber.stringify(
target
)}`
)
}
editor.apply({
type: 'set_selection',
properties: selection,
newProperties: target,
})
}
View on GitHub (pinned to 72a37c701e)
Solutions
- Pass a complete Range {anchor, focus}, or a Point/Path/Range object created via Range.isRange-valid data
- Use Point refs or Editor.point(editor, at) to build a valid full target
- If target may be partial, merge it with editor.selection when it exists, else require both bounds
Example fix
// before
Transforms.select(editor, { anchor }) // selection is null, focus missing
// after
Transforms.select(editor, { anchor, focus: anchor }) Defensive patterns
Strategy: type-guard
Validate before calling
if (editor.selection == null && !Range.isRange(target)) {
throw new Error('Provide a full Range when selection is null')
}
Transforms.select(editor, target) Type guard
const isSelectableTarget = (t: unknown): t is Range | Point => Range.isRange(t) || Point.isPoint(t) || Path.isPath(t)
Prevention
- Always pass {anchor, focus} (or a Point/Path) to Transforms.select
- Validate persisted selections with Range.isRange before restoring
- Default missing focus to the anchor value
When it happens
Trigger: Transforms.select(editor, { anchor: point }) with selection null; passing a partial Range-like object when the editor was never selected or after deselect(); passing a malformed target (string, number, or object missing anchor/focus).
Common situations: Restoring a saved selection from localStorage where focus was dropped; programmatic focus-after-mount before any user selection; spread of optional props producing an incomplete range.
Related errors
- Cannot apply an incomplete "set_selection" operation propert
- Cannot remove the "${key}" selection property
- Cannot resolve a Slate range from a DOM event: ${event}
- Cannot resolve a DOM point from Slate point: ${Scrubber.stri
- Cannot resolve a Slate point from DOM point: ${domPoint}
AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27).
Data as JSON: /api/errors/8aa12748f751cd0d.
Report an issue: GitHub.