-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onCopy not firing for a collapsed selection using React 17 in firefox #4513
Comments
The code for onCopy is pretty terse: slate/packages/slate-react/src/components/editable.tsx Lines 816 to 827 in 48b7129
My best guess is that the following is true in FF but also in other browsers: if (
hasEditableTarget(editor, event.target) &&
!isEventHandled(event, attributes.onCopy)
) { which then prevents the default event, and then calls setFragmentData, but if the selection is empty, setFragment data returns: slate/packages/slate-react/src/plugin/with-react.ts Lines 134 to 138 in 48b7129
|
@dylans thanks for looking into it 😄. If I add an event listener breakpoint for the As for the |
I'm experiencing the same. What is interesting is that it works in the images example (https://www.slatejs.org/examples/images), but not when I try to do the same in my code. If you only select a void block in Firefox, However if I press I suspect it is related to there not being a real DOM-range set and Firefox thinks nothing is selected and this will not fire the events. I see we have some special Firefox code hacks here and there ( |
I'm drafting a PR with a potential fix for this: #4775 |
@skogsmaskin Do you use react 17.x in your code? The examples in slate are run using 16.x I think. I don't quite remember 100% but I thought this only occurred in react 17 for me. If that's the case then there might be some extra code in react 17 that prevents the oncopy event from being triggered or something. In any case thanks for looking into this 😄 |
Also just debugging this is very inconsistent, I have no idea what's going on for example here I have the exact same codesandboxes and it works in one and not the other? 😕 Working https://codesandbox.io/s/slate-react-17-oncopy-bug-working-twndi?file=/index.js (and trying a little later both work again 🤯) Perhaps it's some kind of async problem? |
From #4775 (comment) It's a react bug, see facebook/react#23094 |
Description
See title and codesandbox, been trying to debug this in a react example without luck so it does seem a bug in slate although it only happens when using react 17 and only in firefox
Sandbox
https://codesandbox.io/s/slate-react-17-oncopy-bug-t54vc?file=/index.js
(make sure to open the example in a new window in firefox
Steps
Expectation
onCopy is triggered
Environment
The text was updated successfully, but these errors were encountered: