mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 10:14:02 +02:00
Update findDocumentOrShadowRoot
to return the root node instead of throwing unnecessarily (#4427)
* Update `findDocumentOrShadowRoot` to return undefined instead of throwing unnecessarily * Small refactoring to improve the diff for reviewers * Add changeset for patch * Update new-trainers-peel.md * Resolve PR comments * Revert undefined checks, return window.document and update changeset * Simplify findDocumentOrShadowRoot based on PR feedback * Re-run CI Thanks everyone for your review and thanks @ben10code for your first contribution!
This commit is contained in:
@@ -106,23 +106,14 @@ export const ReactEditor = {
|
||||
const el = ReactEditor.toDOMNode(editor, editor)
|
||||
const root = el.getRootNode()
|
||||
|
||||
// The below exception will always be thrown for iframes because the document inside an iframe
|
||||
// does not inherit it's prototype from the parent document, therefore we return early
|
||||
if (el.ownerDocument !== document) return el.ownerDocument
|
||||
if (
|
||||
(root instanceof Document || root instanceof ShadowRoot) &&
|
||||
root.getSelection != null
|
||||
) {
|
||||
return root
|
||||
}
|
||||
|
||||
if (!(root instanceof Document || root instanceof ShadowRoot))
|
||||
throw new Error(
|
||||
`Unable to find DocumentOrShadowRoot for editor element: ${el}`
|
||||
)
|
||||
|
||||
// COMPAT: Only Chrome implements the DocumentOrShadowRoot mixin for
|
||||
// ShadowRoot; other browsers still implement it on the Document
|
||||
// interface. (2020/08/08)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot#Properties
|
||||
if (root.getSelection === undefined && el.ownerDocument !== null)
|
||||
return el.ownerDocument
|
||||
|
||||
return root
|
||||
return el.ownerDocument
|
||||
},
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user