diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 78323d604bd..d679ff0dd3f 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1741,7 +1741,11 @@ impl Document { self.process_deferred_scripts(); }, LoadType::PageSource(_) => { - if self.has_browsing_context { + if self.has_browsing_context && self.is_fully_active() { + // Note: if the document is not fully active, the layout thread will have exited already. + // The underlying problem might actually be that layout exits while it should be kept alive. + // See https://github.com/servo/servo/issues/22507 + // Disarm the reflow timer and trigger the initial reflow. self.reflow_timeout.set(None); self.upcast::().dirty(NodeDamage::OtherNodeDamage); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 23d7adcf012..1724a6b2276 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1314,6 +1314,10 @@ impl ScriptThread { // into this loop too, but for now it's only images. debug!("Issuing batched reflows."); for (_, document) in self.documents.borrow().iter() { + // Step 13 + if !document.is_fully_active() { + continue; + } let window = document.window(); let pending_reflows = window.get_pending_reflow_count(); if pending_reflows > 0 { diff --git a/tests/wpt/metadata/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/active.window.js.ini b/tests/wpt/metadata/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/active.window.js.ini index c03333ff354..93a9dfe98cf 100644 --- a/tests/wpt/metadata/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/active.window.js.ini +++ b/tests/wpt/metadata/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/active.window.js.ini @@ -1,5 +1,4 @@ [active.window.html] - expected: CRASH [document.open() removes the document's children (non-active document without an associated Window object; createHTMLDocument)] expected: FAIL