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

[react-events] Ensure updateEventListeners updates in commit phase #16540

Merged

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Aug 22, 2019

This is a follow up to the comment @sebmarkbage pointed out in #16532 (comment). Notably, we should only be updating EventResponder instances in the commit phase. EventResponder instances should continue to mount in the complete phase.

I also managed to resolve the issue that prevented us from moving the event fiber logic into the ReactFiberEvents file, as that logic is now shared between the complete and commit phase files.

@sizebot
Copy link

sizebot commented Aug 22, 2019

Details of bundled changes.

Comparing: 507f0fb...22508f2

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-dev.js -0.0% -0.0% 933.25 KB 932.98 KB 206.46 KB 206.43 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 57.19 KB 57.19 KB 15.73 KB 15.73 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.78 KB 3.78 KB 1.53 KB 1.53 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 11.2 KB 11.2 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.2 KB 1.2 KB 701 B 702 B UMD_PROD
react-dom-test-utils.production.min.js 0.0% -0.1% 10.98 KB 10.98 KB 4.08 KB 4.08 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.04 KB 1.04 KB 632 B 633 B NODE_PROD
react-dom.development.js 0.0% -0.0% 908.85 KB 908.86 KB 206.33 KB 206.31 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 111.58 KB 111.58 KB 35.99 KB 36 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 114.98 KB 114.98 KB 37 KB 37 KB UMD_PROFILING
react-dom.development.js 0.0% -0.0% 903.14 KB 903.15 KB 204.72 KB 204.7 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 111.54 KB 111.54 KB 35.39 KB 35.39 KB NODE_PROD
ReactDOM-prod.js -0.0% -0.1% 369.51 KB 369.49 KB 67.78 KB 67.74 KB FB_WWW_PROD
ReactDOM-profiling.js -0.1% -0.0% 374.71 KB 374.23 KB 68.82 KB 68.78 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.71 KB 60.71 KB 15.85 KB 15.85 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.75 KB 10.75 KB 3.68 KB 3.68 KB UMD_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js 0.0% -0.0% 649.76 KB 649.78 KB 141.82 KB 141.78 KB UMD_DEV
react-art.development.js 0.0% -0.0% 580.63 KB 580.65 KB 124.43 KB 124.38 KB NODE_DEV
react-art.production.min.js 0.0% 0.0% 66.83 KB 66.83 KB 20.37 KB 20.37 KB NODE_PROD
ReactART-dev.js -0.0% -0.1% 595.92 KB 595.66 KB 124.2 KB 124.09 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.2% 🔺+0.1% 221.41 KB 221.93 KB 37.73 KB 37.76 KB FB_WWW_PROD

Generated by 🚫 dangerJS

@trueadm trueadm requested a review from gaearon August 22, 2019 12:39
const prevListeners = oldProps.listeners;
const nextListeners = newProps.listeners;
if (prevListeners !== nextListeners) {
updateEventListeners(nextListeners, instance, finishedWork);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main change of this PR.

if (prevListeners !== nextListeners) {
updateEventListeners(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where we used to update Event Responders

rootContainerInstance,
workInProgress,
);
updateEventListeners(listeners, instance, workInProgress);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where we mount Event Responders

rootContainerInstance,
workInProgress,
);
updateEventListeners(listeners, instance, workInProgress);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where we mount Event Responders

@@ -1258,156 +1229,4 @@ function completeWork(
return null;
}

function mountEventResponder(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this code block into ReactFiberEvents

@trueadm trueadm changed the title [Flare] Ensure updateEventListeners updates in commit phase [react-events] Ensure updateEventListeners updates in commit phase Aug 22, 2019
@sebmarkbage
Copy link
Collaborator

Looks like when you added back the @flow annotation, the coverage was enabled again and surfaced a Flow error.

): ReactDOMEventResponderInstance {
// Listen to events
const doc = rootContainerInstance.ownerDocument;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that we originally built the old event system around the rootContainerInstance so that we had the option to move to a model where we attach the listeners on the rootContainerInstance instead of the ownerDocument. The idea was that if you attach it on the root, then it doesn't interfere with siblings trees and stopping propagation can stop it to non-React parents. That's why rootContainerInstance is passed around everywhere even though it doesn't really matter much which one is used (other than for portals into iframes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, but we never actually use it and it saves having to store the rootContainerInstance somewhere to be be passed in during the commit phase (which is why I removed it, as I couldn't see an easy way to get it in the commit phase again).

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

You need to update ReactNativeHostConfig too before landing but the fundamentals here look right.

@trueadm trueadm merged commit fc80772 into facebook:master Aug 22, 2019
@trueadm trueadm deleted the ensure-flare-components-update-in-commit-phase branch August 22, 2019 22:58
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants