diff --git a/.changeset/beige-hotels-vanish.md b/.changeset/beige-hotels-vanish.md new file mode 100644 index 000000000..9bf8ad8b7 --- /dev/null +++ b/.changeset/beige-hotels-vanish.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +weak guard on DataTransfer to not rely on current window diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 1623c9b99..bbdc35a3e 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -429,9 +429,11 @@ export const Editable = (props: EditableProps) => { state.isComposing = false } - const window = ReactEditor.getWindow(editor) - if (data instanceof window.DataTransfer) { - ReactEditor.insertData(editor, data as DataTransfer) + // use a weak comparison instead of 'instanceof' to allow + // programmatic access of paste events coming from external windows + // like cypress where cy.window does not work realibly + if (data?.constructor.name === 'DataTransfer') { + ReactEditor.insertData(editor, data) } else if (typeof data === 'string') { // Only insertText operations use the native functionality, for now. // Potentially expand to single character deletes, as well.