Skip to content
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

pasteOnCapture triggers when the DOM event is in the bubbling phase #8909

Closed
intentionally-left-nil opened this issue Feb 1, 2017 · 4 comments

Comments

@intentionally-left-nil
Copy link

intentionally-left-nil commented Feb 1, 2017

Do you want to request a feature or report a bug?
BUG
What is the current behavior?
When setting up an onPaste handler, react provides two choices: onPaste, or onPasteCapture. In both cases, the DOM event.currentTarget is the #document (which is reasonable given how react's delegate behavior works), but the eventPhase is 3 (aka bubbling) in BOTH cases.

**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar
http://jsbin.com/dacolavipe/edit?js,console,output

What is the expected behavior?
Expected is that onPasteCapture fires when the DOM event is in the capture phase. This is needed to be able to manipulate the paste handler properly when playing focus games on Edge

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Latest version of React, affects at least Chrome and Edge, but I suspect it is browser/OS independent.

@mikekreeki
Copy link

mikekreeki commented Feb 18, 2017

React uses one global event handler per event type and for paste event this handler is always called in bubbling phase in DOM (might be capture for some other event types).

As for eventPhase property on SyntheticEvent it looks like React juts copies native event's eventPhase onto SyntheticEvent (therefore will be always 3 in this case). Then it gathers all the handlers into event._dispatchListeners simulating capture/bubble phases to get them. Those events will be later run in event queue which does not know at this point in which (synthetic) phrase the handler was gathered. This works the same for other events too. When reimplementing event system, it does not change this value accordingly when calling provided callbacks.

@aweary
Copy link
Contributor

aweary commented Feb 18, 2017

We do listen for some events during the capture phase, so it should be possible to handle the event during the correct phase. I'll have to look into it more 🤔

@mikekreeki
Copy link

I checked the code and edited my comment to clarify but you were faster 👍

@gaearon
Copy link
Collaborator

gaearon commented Oct 4, 2017

Let's track this in #9783.

@gaearon gaearon closed this as completed Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants