You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Synthetic eventPhase doesn't reflect the synthetic phase #9783
Demo shows that event phase in onClickCapture for react is incorrect: it's bubbling, but must be capturing. Moreover, event.nativeEvent also shows bubbling phase, so probably the reason is not in syntethic event.
What is the expected behavior? onClickCapture calls during capturing phase onClick calls during bubbling phase
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react version: 15.5.4
os: win7
did this work? don't know
Reacted by Vitaly P., Vladimir Katushenok, Alex, Kote Kutalia and Iv Ov
I think that syntethic event just trigger bubbling phase instead of capturing phase causing of react use bubbling event to simulate capturing event, they would use the unified type event to trigger event that user registered in event array
I don't think it "doesn't work". Capturing itself works as expected.
The part that doesn't work is eventPhase property. The reason it doesn't work is a bit confusing.
React simulates a capturing and a bubbling phase. In reality there's just one (often top-level) event, but React walks the component tree to simulate two phases. The DOM event is caught at bubbling phase (in many cases), but React still simulates both phases based on it.
The problem is React fills all properties from DOM event by default. So you see the bubbling eventPhase in both onClick and onClickCapture because the real DOM event was caught at bubbling phase. Synthetic capture phase of React is not reflected there.
I'm not sure whether it's something that should be fixed. I guess if you send a PR to change eventPhase during event dispatch, we could consider it. I don't know that code that well.
For now I'll tag it as a bug but it will probably be low priority because checking eventPhase seems like a very rare use case.
So, as far as I understood, event phases are simulated in correct order: capturing phase from body to target at first and bubbling phase from target to body at the end. But eventPhase property just doesn't change it's value and is always equals 3 (bubbling phase constant). Am I correct?
Not convinced this is important. The abstraction is a bit leaky anyway. I don't think we necessarily have to normalize this because I'm not sure in which real world scenarios you actually care about eventPhase. And adding bytes to support this doesn't seem worth it.
I just came to the same conclusion but wasted an hour of my time. I was working on a demo to demonstrate how events work in react, and I wanted to use the eventPhase property to log the phase. Mine is not a mission critical scenario, but it would be nice to have this fixed so that people don't spin wheels debugging in the future.
Activity
mfoonirlee commentedon Jun 7, 2017
I think that syntethic event just trigger bubbling phase instead of capturing phase causing of react use bubbling event to simulate capturing event, they would use the unified type event to trigger event that user registered in event array
likerRr commentedon Jun 7, 2017
I just can't understand, if I'm the only who use capturing phase? Or I'm the only who does it wrong? 😄 Strange, that such issue exists.
gaearon commentedon Jul 11, 2017
I don't think it "doesn't work". Capturing itself works as expected.
The part that doesn't work is
eventPhaseproperty. The reason it doesn't work is a bit confusing.React simulates a capturing and a bubbling phase. In reality there's just one (often top-level) event, but React walks the component tree to simulate two phases. The DOM event is caught at bubbling phase (in many cases), but React still simulates both phases based on it.
The problem is React fills all properties from DOM event by default. So you see the bubbling
eventPhasein bothonClickandonClickCapturebecause the real DOM event was caught at bubbling phase. Synthetic capture phase of React is not reflected there.I'm not sure whether it's something that should be fixed. I guess if you send a PR to change
eventPhaseduring event dispatch, we could consider it. I don't know that code that well.For now I'll tag it as a bug but it will probably be low priority because checking
eventPhaseseems like a very rare use case.[-]Event's capturing phase doesn't work[/-][+]Synthetic eventPhase doesn't reflect the synthetic phase[/+]likerRr commentedon Jul 14, 2017
So, as far as I understood, event phases are simulated in correct order: capturing phase from body to target at first and bubbling phase from target to body at the end. But
eventPhaseproperty just doesn't change it's value and is always equals 3 (bubbling phase constant). Am I correct?gaearon commentedon Jul 14, 2017
I think this is right. Although I wouldn't exclude a possibility that we listen to capturing phase ourselves for some events. I haven't checked.
aweary commentedon Oct 4, 2017
For reference, I made a quick effort at resolving this in #10722
gaearon commentedon Jan 5, 2018
Not convinced this is important. The abstraction is a bit leaky anyway. I don't think we necessarily have to normalize this because I'm not sure in which real world scenarios you actually care about
eventPhase. And adding bytes to support this doesn't seem worth it.Noyabronok commentedon Apr 4, 2018
I just came to the same conclusion but wasted an hour of my time. I was working on a demo to demonstrate how events work in react, and I wanted to use the
eventPhaseproperty to log the phase. Mine is not a mission critical scenario, but it would be nice to have this fixed so that people don't spin wheels debugging in the future.gaearon commentedon Jul 24, 2020
We've made a (much bigger) change to actually register Capture events in the Capture phase. So this should be resolved in React 17.