Skip to content

Commit

Permalink
fix: use ownerDocument to create element (#4661)
Browse files Browse the repository at this point in the history
* fix: use ownerDocument to create element

* chore: add changeset
  • Loading branch information
leoc4e authored Nov 20, 2021
1 parent 3ad3aac commit 0f194a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-dolphins-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

use ownerDocument to create element
8 changes: 4 additions & 4 deletions packages/slate-react/src/plugin/with-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const withReact = <T extends Editor>(editor: T) => {
// in the HTML, and can be used for intra-Slate pasting. If it's a text
// node, wrap it in a `<span>` so we have something to set an attribute on.
if (isDOMText(attach)) {
const span = document.createElement('span')
const span = attach.ownerDocument.createElement('span')
// COMPAT: In Chrome and Safari, if we don't add the `white-space` style
// then leading and trailing spaces will be ignored. (2017/09/21)
span.style.whiteSpace = 'pre'
Expand All @@ -184,13 +184,13 @@ export const withReact = <T extends Editor>(editor: T) => {
data.setData('application/x-slate-fragment', encoded)

// Add the content to a <div> so that we can get its inner HTML.
const div = document.createElement('div')
const div = contents.ownerDocument.createElement('div')
div.appendChild(contents)
div.setAttribute('hidden', 'true')
document.body.appendChild(div)
contents.ownerDocument.body.appendChild(div)
data.setData('text/html', div.innerHTML)
data.setData('text/plain', getPlainText(div))
document.body.removeChild(div)
contents.ownerDocument.body.removeChild(div)
return data
}

Expand Down

0 comments on commit 0f194a8

Please sign in to comment.