-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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(test): disable preventDefault() for beforeunload event #18911
fix(test): disable preventDefault() for beforeunload event #18911
Conversation
This seems more like a bandaid rather than fixing the underlying problem - I believe the root cause is the one described in #16928 that I wanted to fix in the coming days (we now have all the ingredients to properly fix it). I'm not in favor by altering the behavior of |
I don't think it's a band-aid. It's possible there are other issues that lead to the following block being needed: deno/ext/node/polyfills/process.ts Lines 736 to 742 in 10ae5ee
But while investigating it I noticed the inconsistency of whether or not the event loop is allowed to run to completion after a test run. This PR consolidates on the typical case where it doesn't, rather than only doing it if there's a beforeunload handler which prevents default. It happens to fix that issue.
|
The only alternative to this as I described in #18910 (comment) is to always call |
Not really - there are no other issues that led to this block looking like it does, besides I had no other way to polyfill this event when this code lived in
Again, there was no good reason, besides the fact that I wasn't able to polyfill it in any other way at the time of writing that code, which as the linked issue described is actually buggy.
Maybe, still it feels a little strange that in @dsherret @lucacasonato thoughts on this? |
I was referring to #18910. Does the reproduction you're using for #16928 also use This is related to a separate issue of whether or not to allow the event loop to complete in a test module after finishing tests. Currently // Run event loop to completion, same as `deno run`.
worker.run_event_loop(false).await?;
loop {
if !worker.dispatch_beforeunload_event(located_script_name!())? {
break;
}
worker.run_event_loop(false).await?;
}
worker.dispatch_unload_event(located_script_name!())?; Or like this: // Don't run event loop, run unload events but don't allow them to prevent default.
!worker.dispatch_beforeunload_event(located_script_name!())?;
worker.dispatch_unload_event(located_script_name!())?; But currently it looks like this: // Don't run event loop typically, run unload events and run the event loop if they prevent default.
loop {
if !worker.dispatch_beforeunload_event(located_script_name!())? {
break;
}
worker.run_event_loop(false).await?;
}
worker.dispatch_unload_event(located_script_name!())?; I think the first one is disruptive because existing code which might rely on the worker and its open resources being dropped after tests are finished would start to hang with no info. The second is what would normally happen currently but with the edge case smoothed off. Thoughts? |
No, the reproduction uses
Sorry for slow response. Wouldn't the first case immediately break the loop once I asked other team members to take a look at this PR. If there are no objections I'll land it as is. We can change the behavior if needed once I fix #16928. |
The relevant line is the invariant |
Exactly :D how does it even work currently if we're not polling the event loop? Am I missing something simple here? I guess it's because of |
Yep, the same was true since |
Okay, that makes sense. Sorry for back and forth on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, once the comments are added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #18910.