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
Member

@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 (#19156, #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.

@codesandbox
Copy link

@codesandbox codesandbox 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
@gaearon gaearon force-pushed the gaearon:fixscroll branch from 5a38bac to 21813de Jul 27, 2020
@sizebot
Copy link

@sizebot 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 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
Member

@trueadm trueadm left a comment

Great stuff :)

@sebmarkbage
Copy link
Member

@sebmarkbage sebmarkbage commented Jul 27, 2020

What does onScrollCapture do?

@gaearon
Copy link
Member Author

@gaearon gaearon commented Jul 27, 2020

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

@gaearon
Copy link
Member Author

@gaearon gaearon commented Jul 27, 2020

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

@gaearon gaearon force-pushed the gaearon:fixscroll branch from 21813de to 1c2db6b Jul 27, 2020
@gaearon
Copy link
Member Author

@gaearon gaearon commented Jul 27, 2020

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

@gaearon
Copy link
Member Author

@gaearon gaearon commented Jul 27, 2020

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

@gaearon gaearon merged commit 06d104e into facebook:master Jul 27, 2020
31 of 32 checks passed
31 of 32 checks passed
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_build CircleCI is running your tests
Details
Facebook CLA Check Contributor License Agreement is valid!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_build Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_lint_build Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_build_prod Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_dom_fixtures Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_persistent Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_prod Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_prod_www Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_prod_www_variant Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_www Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_www_variant Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts_experimental Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: sizebot_experimental Your tests passed on CircleCI!
Details
ci/circleci: sizebot_stable Your tests passed on CircleCI!
Details
ci/circleci: yarn_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_flow Your tests passed on CircleCI!
Details
ci/circleci: yarn_lint Your tests passed on CircleCI!
Details
ci/circleci: yarn_lint_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_test Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build_devtools Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_prod_www Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_prod_www_variant Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_www Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_www_variant Your tests passed on CircleCI!
Details
ci/codesandbox Building packages succeeded.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.