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

Don't emulate bubbling of the scroll event #19464

Merged
merged 2 commits into from
Jul 27, 2020
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 27, 2020

Currently, scroll event is somewhat broken on master.

This will fire both handlers if we scroll the child:

<div onScroll={onParentScroll}>
  <div onScroll={onChildScroll} />
</div>

But this will not fire the parent handler if we scroll the child:

<div onScroll={onParentScroll}>
  <div />
</div>

In other words, bubbling the scroll event currently doesn't work if the event target itself doesn't have a React listener.

This is a regression in the modern system.

Possible Fixes

This is based on @trueadm's writeup.

  • Option 1: Add native scroll handler to every div so that we can't "miss" the event — whether it has a React handler or not. This is a similar strategy we use for other events that don't bubble in the browser (e.g. toggle, invalid, play, etc). However, for those cases, we know which elements need it (e.g. audio and video). Adding a scroll listener to every single div seems untenable. So this is ruled out for performance reasons.

  • Option 2 (Breaking Change): Stop emulating bubbling for onScroll. It it confusing anyway (Bug: Strange onScroll behaviour when child editing #19156, Strange onScroll behaviour #15723). This is what this PR does. The downside is that now this event is special and different from all others.

  • Option 3 (Even Bigger Breaking Change): Stop emulating bubbling for all events that don't bubble in the browser. This includes invalid, load, toggle, close, cancel, and media events. We could consider this but it's a bigger breaking change. Arguably, some of them, like onInvalid, are actually useful and not too confusing to bubble. So I think this needs to wait until 18.

  • Option 4 (Status Quo): We could go back to React 16 behavior, which attaches onScroll in the capture phase. That would solve the current inconsistency, but wouldn't be in line with our strategy for how nested Reacts should work. It also wouldn't solve the problem that bubbling onScroll is inherently confusing.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jul 27, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 189132c:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Jul 27, 2020

Details of bundled changes.

Comparing: 217ecf5...189132c

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.0% -0.0% 886.01 KB 885.97 KB 202.93 KB 202.92 KB NODE_DEV
ReactDOMForked-prod.js 0.0% 🔺+0.1% 408.26 KB 408.36 KB 75.37 KB 75.43 KB FB_WWW_PROD
react-dom.production.min.js 0.0% -0.0% 119.43 KB 119.43 KB 38.4 KB 38.4 KB NODE_PROD
ReactDOMForked-profiling.js 0.0% +0.1% 423.33 KB 423.43 KB 78 KB 78.06 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 0.0% 12.84 KB 12.84 KB 5.03 KB 5.03 KB UMD_PROD
ReactDOMTesting-dev.js -0.0% -0.0% 986.64 KB 986.59 KB 220.22 KB 220.22 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 60.88 KB 60.88 KB 17.65 KB 17.65 KB NODE_DEV
ReactTestUtils-dev.js +0.1% +0.1% 55.22 KB 55.29 KB 15.48 KB 15.49 KB FB_WWW_DEV
react-dom.development.js -0.0% -0.0% 930.75 KB 930.71 KB 205.41 KB 205.4 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 119.33 KB 119.33 KB 39.09 KB 39.09 KB UMD_PROD
ReactDOMForked-dev.js 0.0% 0.0% 1021.85 KB 1022.17 KB 226.46 KB 226.57 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% -0.0% 123.49 KB 123.49 KB 39.68 KB 39.68 KB NODE_PROFILING
ReactDOM-dev.js 0.0% 0.0% 1018.51 KB 1018.83 KB 226.15 KB 226.26 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 🔺+0.1% 406.8 KB 406.9 KB 75.06 KB 75.13 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% +0.1% 421.26 KB 421.36 KB 77.68 KB 77.74 KB FB_WWW_PROFILING
ReactDOMServer-dev.js 0.0% 0.0% 147.37 KB 147.44 KB 37.43 KB 37.44 KB FB_WWW_DEV

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against 189132c

@sizebot
Copy link

sizebot commented Jul 27, 2020

Details of bundled changes.

Comparing: 217ecf5...189132c

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.0% -0.0% 923.13 KB 923.08 KB 209.73 KB 209.72 KB NODE_DEV
ReactDOMForked-prod.js 0.0% 🔺+0.1% 397.13 KB 397.23 KB 73.73 KB 73.78 KB FB_WWW_PROD
react-dom.production.min.js 0.0% -0.0% 124.23 KB 124.23 KB 39.85 KB 39.85 KB NODE_PROD
ReactDOMForked-profiling.js 0.0% +0.1% 412.14 KB 412.24 KB 76.37 KB 76.42 KB FB_WWW_PROFILING
ReactDOMTesting-dev.js -0.0% -0.0% 958.48 KB 958.43 KB 214.81 KB 214.8 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 60.89 KB 60.89 KB 17.66 KB 17.66 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 5.61 KB 5.61 KB 1.86 KB 1.87 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 12.71 KB 12.71 KB 4.97 KB 4.97 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 5.36 KB 5.36 KB 1.8 KB 1.8 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.17 KB 1.17 KB 667 B 666 B NODE_PROD
ReactTestUtils-dev.js +0.1% +0.1% 55.22 KB 55.29 KB 15.49 KB 15.5 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 4.87 KB 4.87 KB 1.7 KB 1.71 KB NODE_DEV
react-dom.development.js -0.0% -0.0% 969.66 KB 969.62 KB 212.28 KB 212.27 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 124.08 KB 124.08 KB 40.6 KB 40.6 KB UMD_PROD
ReactDOMForked-dev.js 0.0% 0.0% 996.31 KB 996.63 KB 221.74 KB 221.84 KB FB_WWW_DEV
ReactDOM-dev.js 0.0% 0.0% 992.97 KB 993.29 KB 221.46 KB 221.57 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 🔺+0.1% 395.67 KB 395.77 KB 73.44 KB 73.5 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% +0.1% 410.07 KB 410.17 KB 76.07 KB 76.12 KB FB_WWW_PROFILING
ReactDOMServer-dev.js 0.0% +0.1% 143.33 KB 143.41 KB 36.43 KB 36.45 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% -0.0% 65.91 KB 65.91 KB 18.18 KB 18.18 KB UMD_DEV

Size changes (experimental)

Generated by 🚫 dangerJS against 189132c

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff :)

@sebmarkbage
Copy link
Collaborator

What does onScrollCapture do?

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 27, 2020

Not sure what you mean. It does regular capturing? That mirrors the browser behavior AFAIK.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 27, 2020

Meaning, it would currently capture at the root and call React capture listeners.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 27, 2020

I'm thinking this is worth putting behind a flag. Kind of risky.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 27, 2020

I'm gonna land this behind a flag so we can quickly roll back if something's broken.

This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants