ianstormtaylor/slate · error · Error
The ref prop of a token cannot be used with the path prop.
Error message
The ref prop of a token cannot be used with the path prop.
What it means
In slate-hyperscript token tags (<text>, <inline>, <block>, etc.), a ref prop and a path prop are mutually exclusive. The ref mechanism works by having the token record the path where it ends up in the editor tree at render time, while path explicitly hardcodes the location. Passing both is contradictory, so the token constructor throws immediately.
Source
Thrown at packages/slate-hyperscript/src/tokens.ts:44
export class Token<Ref = unknown> {
offset?: number
path?: Path
ref?: Ref
constructor(
props: {
offset?: number
path?: Path
ref?: Ref
} = {}
) {
const { offset, path, ref } = props
this.offset = offset
this.path = path
if (ref) {
if (path != null) {
throw new Error(
'The ref prop of a token cannot be used with the path prop.'
)
}
this.ref = ref
}
}
}
/**
* Anchor tokens represent the selection's anchor point.
*/
export class AnchorToken extends Token<HyperscriptRangeRef> {}
/**
* Focus tokens represent the selection's focus point.
*/
View on GitHub (pinned to 72a37c701e)
Solutions
- Remove the path prop and let the ref capture the path from the editor tree
- Or remove the ref prop and keep using the explicit path if you don't need a ref object
Example fix
// before
<editor>
<text path={[0]} ref={t}>hello</text>
</editor>
// after
<editor>
<text ref={t}>hello</text>
</editor> Defensive patterns
Strategy: validation
Validate before calling
if (props.ref != null && props.path != null) {
throw new Error('ref and path are mutually exclusive on tokens')
}
// before rendering the token Type guard
const hasConflictingProps = (p) => p.ref != null && p.path != null
Prevention
- Never combine path and ref on slate-hyperscript token tags
- Prefer refs over hardcoded paths in modern tests
When it happens
Trigger: Writing <text path={[0,0]} ref={t}>hi</text>; passing a props object containing both path and ref to any token tag created by createHyperscript.
Common situations: Migrating old tests that used explicit path props and adding refs without removing path; copy-pasting token markup and forgetting to delete the path prop.
Related errors
- A HyperscriptPointRef must be passed as the ref prop of a <p
- A HyperscriptRangeRef must be passed as the ref prop of an <
- A HyperscriptRangeRef must be passed as the ref prop of a <f
AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27).
Data as JSON: /api/errors/65cd60bfe6c24782.
Report an issue: GitHub.