Repository navigation
Fix clipboard if content editable is in an iframe. - #4649
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
zurfyx
left a comment
There was a problem hiding this comment.
Thank you for addressing this, left a small comment regarding how we do the instanceof comparison. We have be careful it works fine for headless mode, including JSDOM which is quite popular. I proposed a similar approach to what we use for importDOM, where instead of instance checks we look for specific properties instead. It's not as type-safe but it will work for non-browser environments.
| event instanceof getClassFromEditorWindow(editor, ClipboardEvent) | ||
| ? event | ||
| : null, |
There was a problem hiding this comment.
| event instanceof getClassFromEditorWindow(editor, ClipboardEvent) | |
| ? event | |
| : null, | |
| Object.getPrototypeOf(event).constructor.name === ClipboardEvent.name ? event : null, |
where ClipboardEvent.name would be hoisted
Given that we're also using this in the Clipboard module we can also abstract this on a clipboard exported function.
There was a problem hiding this comment.
That's a good idea! I updated the PR using the new approach and not relying on the window object. I've created a util function that at least makes TypeScript happy about it.
6e0681d to
71bb193
Compare
71bb193 to
09ca91a
Compare
09ca91a to
0a8774e
Compare
zurfyx
left a comment
There was a problem hiding this comment.
LGTM, thank you for iterating on this!
This is also my first contribution attempt to the project. Sorry in advance if something doesn't make sense!
In #2108 we support for iframe (use React.Portal to render the content editable area in an iframe). It works well.
Recently I notice that some of the clipboard logic doesn't work in iframe. More specifically, I found that
DecoratorNodewon't be exported on copy.After digging into it, I found that is caused by global class variables having different instances in different window. There is more detail about this behaviour in MDN.
In this diff, the issue I personally encounter has been fixed. But there are wider usage of
instanceofin the codebase.Overall, I want to hear from maintainers about
_windowfromLexicalEditor<Editor />for usage with iframe