script: extend the prevention of the firing of load events to all iframes (#40401)

This extends the preventing of the firing of the load events when there
is a pending navigation from the initial blank document only to all
iframes. Part of https://github.com/servo/servo/issues/31973

Testing: tests/wpt/mozilla/tests/mozilla/FileAPI/file-upload.html
Fixes: This should fix the intermittency of
https://github.com/servo/servo/issues/40348

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
Gregory Terzian
2025-11-07 23:47:36 +08:00
committed by GitHub
parent 38d977343c
commit 933ebe428d
3 changed files with 14 additions and 3 deletions

View File

@@ -576,12 +576,21 @@ impl HTMLIFrameElement {
// for the initial blank document if we know that a navigation is ongoing,
// which can be deducted from `pending_navigation` or the presence of an src.
//
// Additionally, to prevent a race condition with navigations,
// in all cases, skip the load event if there is a pending navigation.
// See #40348
//
// TODO: run these step synchronously as part of processing the iframe attributes.
let should_fire_event = if self.is_initial_blank_document() {
// If this is the initial blank doc:
// do not fire if there is a pending navigation,
// or if the iframe has an src.
!self.pending_navigation.get() &&
!self.upcast::<Element>().has_attribute(&local_name!("src"))
} else {
true
// If this is not the initial blank doc:
// do not fire if there is a pending navigation.
!self.pending_navigation.get()
};
if should_fire_event {
// Step 6. Fire an event named load at element.