Skip to content

onScroll event propagation #175

@O4epegb

Description

@O4epegb

So, since React bubbles all its events, even the ones that the browser doesn't bubble by default, there is some weird behaviour with onScroll event.

Example: https://codesandbox.io/s/httpsgithubcomreactjsrfcsissues175-viizc

onScroll callback on Parent element is fired when Children element is scrolled.

Why this is weird and might lead to unexpected bugs? Imagine following situation:

  1. You have some scrollable component A where you are doing something when onScroll fires
  2. Then somebody introduces another scrollable component B as a children of your component
  3. When B is scrolled your onScroll handler on component A is also fired.
  4. To mitigate this you need to add some checks like this one: e.target === e.currentTarget

Basically it means that you need to add this check every time you add onScroll to any element because you can not be sure that nothing scrollable will be introduced down the tree later.

I think there are more events like this, for example onSubmit, but at least you can't put <form> inside another <form>.

It might be worth to reconsider event bubbling in the future.

Issue discussion facebook/react#15723

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions