Skip to content

Synthetic eventPhase doesn't reflect the synthetic phase #9783

Closed

Description

@likerRr

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Both onClick and onClickCapture called on bubbling phase.

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 (template: https://jsfiddle.net/84v837e9/).

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.

https://jsbin.com/xebarapije/2/edit?js,console,output

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

Activity

  1. mfoonirlee commented on Jun 7, 2017

    @mfoonirlee

    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

  2. likerRr commented on Jun 7, 2017

    @likerRr
    Author

    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.

  3. gaearon commented on Jul 11, 2017

    @gaearon
    Collaborator

    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.

  4. changed the title [-]Event's capturing phase doesn't work[/-] [+]Synthetic eventPhase doesn't reflect the synthetic phase[/+] on Jul 11, 2017
  5. likerRr commented on Jul 14, 2017

    @likerRr
    Author

    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?

  6. gaearon commented on Jul 14, 2017

    @gaearon
    Collaborator

    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.

  7. aweary commented on Oct 4, 2017

    @aweary
    Contributor

    For reference, I made a quick effort at resolving this in #10722

  8. gaearon commented on Jan 5, 2018

    @gaearon
    Collaborator

    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.

  9. Noyabronok commented on Apr 4, 2018

    @Noyabronok

    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.

  10. gaearon commented on Jul 24, 2020

    @gaearon
    Collaborator

    We've made a (much bigger) change to actually register Capture events in the Capture phase. So this should be resolved in React 17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions