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

Fix development mode hang when iframe is removed #19220

Merged
merged 2 commits into from Jul 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/shared/invokeGuardedCallbackImpl.js
Expand Up @@ -116,12 +116,7 @@ if (__DEV__) {
'event',
);

// Create an event handler for our fake event. We will synchronously
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
// call the user-provided callback.
const funcArgs = Array.prototype.slice.call(arguments, 3);
function callCallback() {
didCall = true;
function restoreAfterDispatch() {
// We immediately remove the callback from event listeners so that
// nested `invokeGuardedCallback` calls do not clash. Otherwise, a
// nested call would trigger the fake event handlers of any call higher
Expand All @@ -138,7 +133,15 @@ if (__DEV__) {
) {
window.event = windowEvent;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder why this doesn't do

if (windowEventDescriptor) {
    Object.defineProperty(window, 'event', windowEventDescriptor);
}

as below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm scared to touch it. #11696 (comment)

}
}

// Create an event handler for our fake event. We will synchronously
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
// call the user-provided callback.
const funcArgs = Array.prototype.slice.call(arguments, 3);
function callCallback() {
didCall = true;
restoreAfterDispatch();
func.apply(context, funcArgs);
didError = false;
}
Expand Down Expand Up @@ -195,7 +198,7 @@ if (__DEV__) {
Object.defineProperty(window, 'event', windowEventDescriptor);
}

if (didError) {
if (didCall && didError) {
if (!didSetError) {
// The callback errored, but the error event never fired.
error = new Error(
Expand Down Expand Up @@ -226,6 +229,7 @@ if (__DEV__) {
// https://github.com/facebook/react/issues/16734
// https://github.com/facebook/react/issues/16585
// Fall back to the production implementation.
restoreAfterDispatch();
return invokeGuardedCallbackProd.apply(this, arguments);
}
};
Expand Down