Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(renderer): keep child modulepreload from delaying load
ldm0b70555cb4a02
diff --git a/moli-renderer-v8/src/document_module_graph/client.rs b/moli-renderer-v8/src/document_module_graph/client.rsindex 27e6c2432..cd478d24d 100644--- a/moli-renderer-v8/src/document_module_graph/client.rs+++ b/moli-renderer-v8/src/document_module_graph/client.rs@@ -2,9 +2,7 @@ use moli_module_script_tree as module_tree;use std::sync::Arc;use crate::dom::native::NativeNodeId;-use crate::frame_owner_model::{- FrameDocumentModulepreloadLinkClient, MainDocumentModulepreloadEventOwner,-};+use crate::frame_owner_model::{DocumentLinkEventOwner, FrameDocumentModulepreloadLinkClient};use super::ModuleMapKey;@@ -16,8 +14,13 @@ use super::ModuleMapKey;pub(crate) struct NativeModulepreloadLinkClient {owner: NativeNodeId,key: ModuleMapKey,- main_document_event_owner: Option<MainDocumentModulepreloadEventOwner>,- frame_document_client: Option<FrameDocumentModulepreloadLinkClient>,+ event_owner: Option<NativeModulepreloadEventOwner>,+}++#[derive(Clone, Copy, Debug, PartialEq, Eq)]+enum NativeModulepreloadEventOwner {+ Main(DocumentLinkEventOwner),+ Child(FrameDocumentModulepreloadLinkClient),}impl NativeModulepreloadLinkClient {@@ -26,21 +29,21 @@ impl NativeModulepreloadLinkClient {Arc::new(Self {owner,key,- main_document_event_owner: None,- frame_document_client: None,+ event_owner: None,})}pub(crate) fn new_with_main_document_event_owner(owner: NativeNodeId,key: ModuleMapKey,- main_document_event_owner: MainDocumentModulepreloadEventOwner,+ main_document_event_owner: DocumentLinkEventOwner,) -> Arc<Self> {Arc::new(Self {owner,key,- main_document_event_owner: Some(main_document_event_owner),- frame_document_client: None,+ event_owner: Some(NativeModulepreloadEventOwner::Main(+ main_document_event_owner,+ )),})}@@ -52,8 +55,7 @@ impl NativeModulepreloadLinkClient {Arc::new(Self {owner,key,- main_document_event_owner: None,- frame_document_client: Some(frame_document_client),+ event_owner: Some(NativeModulepreloadEventOwner::Child(frame_document_client)),})}@@ -65,12 +67,18 @@ impl NativeModulepreloadLinkClient {&self.key}- pub(crate) fn main_document_event_owner(&self) -> Option<MainDocumentModulepreloadEventOwner> {- self.main_document_event_owner+ pub(crate) fn main_document_event_owner(&self) -> Option<DocumentLinkEventOwner> {+ match self.event_owner {+ Some(NativeModulepreloadEventOwner::Main(owner)) => Some(owner),+ Some(NativeModulepreloadEventOwner::Child(_)) | None => None,+ }}pub(crate) fn frame_document_client(&self) -> Option<FrameDocumentModulepreloadLinkClient> {- self.frame_document_client+ match self.event_owner {+ Some(NativeModulepreloadEventOwner::Child(client)) => Some(client),+ Some(NativeModulepreloadEventOwner::Main(_)) | None => None,+ }}pub(crate) fn ptr_eq(left: &Arc<Self>, right: &Arc<Self>) -> bool {diff --git a/moli-renderer-v8/src/frame_owner_model.rs b/moli-renderer-v8/src/frame_owner_model.rsindex 0ae10cc88..f05745081 100644--- a/moli-renderer-v8/src/frame_owner_model.rs+++ b/moli-renderer-v8/src/frame_owner_model.rs@@ -69,14 +69,14 @@ pub(crate) use frame_task_sources::{PendingChildJavascriptUrlDocumentScript,};pub(crate) use lifecycle_tasks::{- ChildDocumentAsyncClassicScriptLoadDelay, FrameDocumentCompleteLifecycleAction,- FrameDocumentDomContentLoadedLifecycleAction, FrameDocumentImageLoadEventBinding,- FrameDocumentInteractiveLifecycleAction, FrameDocumentLifecycleAction,- FrameDocumentLifecycleTaskEffect, FrameDocumentMediaLoadDelayBinding,- FrameDocumentUnloadLifecycleAction, MainDocumentCompleteLifecycleAction,- MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding,- MainDocumentInteractiveLifecycleAction, MainDocumentMediaLoadDelayBinding,- MainDocumentModulepreloadEventOwner, MainDocumentScriptLoadDelayKind,+ ChildDocumentAsyncClassicScriptLoadDelay, DocumentLinkEventOwner,+ FrameDocumentCompleteLifecycleAction, FrameDocumentDomContentLoadedLifecycleAction,+ FrameDocumentImageLoadEventBinding, FrameDocumentInteractiveLifecycleAction,+ FrameDocumentLifecycleAction, FrameDocumentLifecycleTaskEffect,+ FrameDocumentMediaLoadDelayBinding, FrameDocumentUnloadLifecycleAction,+ MainDocumentCompleteLifecycleAction, MainDocumentDomContentLoadedLifecycleAction,+ MainDocumentImageLoadDelayBinding, MainDocumentInteractiveLifecycleAction,+ MainDocumentMediaLoadDelayBinding, MainDocumentScriptLoadDelayKind,MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease,MainDocumentStyleLoadEventBinding, StylesheetSubresourceLoadDelayBinding,};@@ -106,7 +106,6 @@ pub(crate) use module_clients::FrameDocumentModuleTerminalWarningRecord;pub(crate) use module_clients::FrameDocumentModulepreloadEventAction;pub(crate) use module_clients::FrameDocumentModulepreloadEventActionHooks;pub(crate) use module_clients::FrameDocumentModulepreloadEventActionRunner;-pub(crate) use module_clients::FrameDocumentModulepreloadEventBinding;pub(crate) use module_clients::FrameDocumentModulepreloadFetchTask;pub(crate) use module_clients::FrameDocumentModulepreloadLinkClient;pub(crate) use module_clients::FrameDocumentModulepreloadMaterializedWork;diff --git a/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs b/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rsindex 55a3d4c01..6a624156a 100644--- a/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs+++ b/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs@@ -86,7 +86,7 @@ impl MainDocumentScriptLoadDelayLease {////// Stylesheet processing may retain the token across its network load./// `modulepreload` never uses this type; it retains only-/// [`MainDocumentModulepreloadEventOwner`].+/// [`DocumentLinkEventOwner`].#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) struct MainDocumentStyleLoadEventBinding {owner: FrameDocumentTaskOwner,@@ -135,19 +135,19 @@ impl MainDocumentStyleLoadEventBinding {}}-/// Exact Document and element identity retained while a non-blocking-/// `modulepreload` fetch is in flight.+/// Exact Document and element identity for one link event.///-/// This deliberately carries no load-delay token and remains the complete-/// lifecycle identity through terminal acceptance and event publication.+/// This identity deliberately carries no load-delay token. Link types such as+/// `modulepreload` that do not delay `window.load` retain this value directly;+/// load-delaying link types must wrap it in a separate lifecycle binding.#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(crate) struct MainDocumentModulepreloadEventOwner {+pub(crate) struct DocumentLinkEventOwner {owner: FrameDocumentTaskOwner,element: DomHandle,}-impl MainDocumentModulepreloadEventOwner {- pub(super) fn new(owner: FrameDocumentTaskOwner, element: DomHandle) -> Self {+impl DocumentLinkEventOwner {+ pub(crate) fn new(owner: FrameDocumentTaskOwner, element: DomHandle) -> Self {Self { owner, element }}diff --git a/moli-renderer-v8/src/frame_owner_model/module_clients.rs b/moli-renderer-v8/src/frame_owner_model/module_clients.rsindex b7da6f593..b2e66998a 100644--- a/moli-renderer-v8/src/frame_owner_model/module_clients.rs+++ b/moli-renderer-v8/src/frame_owner_model/module_clients.rs@@ -10,6 +10,7 @@ use crate::module_runtime::{};use crate::planning::{PreparedScript, ScriptFetchMetadata};+use super::lifecycle_tasks::DocumentLinkEventOwner;use super::module_graph::{FrameDocumentDynamicImportTerminalPreparedAction, FrameDocumentModuleTerminalQueueFollowup,};@@ -588,7 +589,6 @@ pub(crate) struct FrameDocumentModulepreloadFetchPayload {/// discovery time, preserve it as an additional replacement guard.#[derive(Clone, Debug, PartialEq, Eq)]pub(crate) struct FrameDocumentModulepreloadWorkAwaitingRealm {- owner: FrameDocumentTaskOwner,expected_realm_id: Option<FrameRealmId>,client: FrameDocumentModulepreloadLinkClient,kind: FrameDocumentModulepreloadWorkAwaitingRealmKind,@@ -608,13 +608,11 @@ pub(crate) enum FrameDocumentModulepreloadMaterializedWork {impl FrameDocumentModulepreloadWorkAwaitingRealm {pub(crate) fn fetch_start(- owner: FrameDocumentTaskOwner,expected_realm_id: Option<FrameRealmId>,client: FrameDocumentModulepreloadLinkClient,request: NativeModuleSingleFetchRequest,) -> Self {Self {- owner,expected_realm_id,client,kind: FrameDocumentModulepreloadWorkAwaitingRealmKind::FetchStart(Box::new(request)),@@ -622,12 +620,10 @@ impl FrameDocumentModulepreloadWorkAwaitingRealm {}pub(crate) fn link_error(- owner: FrameDocumentTaskOwner,expected_realm_id: Option<FrameRealmId>,client: FrameDocumentModulepreloadLinkClient,) -> Self {Self {- owner,expected_realm_id,client,kind: FrameDocumentModulepreloadWorkAwaitingRealmKind::LinkError,@@ -635,7 +631,7 @@ impl FrameDocumentModulepreloadWorkAwaitingRealm {}pub(crate) fn owner(&self) -> FrameDocumentTaskOwner {- self.owner+ self.client.owner()}pub(crate) fn expected_realm_id(&self) -> Option<FrameRealmId> {@@ -679,7 +675,6 @@ impl FrameDocumentModulepreloadWorkAwaitingRealm {FrameDocumentModulepreloadWorkAwaitingRealmKind::FetchStart(request) => {FrameDocumentModulepreloadMaterializedWork::FetchStart(Box::new(FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- self.owner,realm_id,self.client,*request,@@ -689,7 +684,6 @@ impl FrameDocumentModulepreloadWorkAwaitingRealm {FrameDocumentModulepreloadWorkAwaitingRealmKind::LinkError => {FrameDocumentModulepreloadMaterializedWork::LinkError(FrameDocumentModulepreloadTerminalWork::from_link_error_parts(- self.owner,realm_id,self.client,),@@ -702,14 +696,18 @@ impl FrameDocumentModulepreloadWorkAwaitingRealm {#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) struct FrameDocumentModulepreloadLinkClient {child_handle: DomHandle,- link_handle: DomHandle,+ event_owner: DocumentLinkEventOwner,}impl FrameDocumentModulepreloadLinkClient {- pub(crate) fn new(child_handle: DomHandle, link_handle: DomHandle) -> Self {+ pub(crate) fn new(+ child_handle: DomHandle,+ owner: FrameDocumentTaskOwner,+ link_handle: DomHandle,+ ) -> Self {Self {child_handle,- link_handle,+ event_owner: DocumentLinkEventOwner::new(owner, link_handle),}}@@ -717,42 +715,12 @@ impl FrameDocumentModulepreloadLinkClient {self.child_handle}- pub(crate) fn link_handle(self) -> DomHandle {- self.link_handle- }-}--#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(crate) struct FrameDocumentModulepreloadEventBinding {- client: FrameDocumentModulepreloadLinkClient,- load_delay_token: Option<DocumentLoadDelayTokenId>,-}--impl FrameDocumentModulepreloadEventBinding {- pub(crate) fn new(- client: FrameDocumentModulepreloadLinkClient,- load_delay_token: Option<DocumentLoadDelayTokenId>,- ) -> Self {- Self {- client,- load_delay_token,- }- }-- pub(crate) fn client(self) -> FrameDocumentModulepreloadLinkClient {- self.client- }-- pub(crate) fn child_handle(self) -> DomHandle {- self.client.child_handle()+ pub(crate) fn owner(self) -> FrameDocumentTaskOwner {+ self.event_owner.owner()}pub(crate) fn link_handle(self) -> DomHandle {- self.client.link_handle()- }-- pub(crate) fn load_delay_token(self) -> Option<DocumentLoadDelayTokenId> {- self.load_delay_token+ self.event_owner.element()}}@@ -947,26 +915,17 @@ pub(crate) struct FrameDocumentModulepreloadEventAction {owner: FrameDocumentTaskOwner,realm_id: FrameRealmId,key: Option<ModuleMapKey>,- binding: FrameDocumentModulepreloadEventBinding,+ client: FrameDocumentModulepreloadLinkClient,successful: bool,}#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]pub(crate) struct FrameDocumentModulepreloadTerminalOutcome {- terminal_work_consumed: bool,event_dispatched: bool,event_dispatch_failed: bool,- load_delay_settled: bool,}impl FrameDocumentModulepreloadTerminalOutcome {- pub(crate) fn terminal_work_consumed() -> Self {- Self {- terminal_work_consumed: true,- ..Self::default()- }- }-pub(crate) fn event_dispatched() -> Self {Self {event_dispatched: true,@@ -981,20 +940,6 @@ impl FrameDocumentModulepreloadTerminalOutcome {}}- pub(crate) fn load_delay_settled() -> Self {- Self {- load_delay_settled: true,- ..Self::default()- }- }-- pub(crate) fn merge(&mut self, other: Self) {- self.terminal_work_consumed |= other.terminal_work_consumed;- self.event_dispatched |= other.event_dispatched;- self.event_dispatch_failed |= other.event_dispatch_failed;- self.load_delay_settled |= other.load_delay_settled;- }-pub(crate) fn event_was_dispatched(self) -> bool {self.event_dispatched}@@ -1003,23 +948,17 @@ impl FrameDocumentModulepreloadTerminalOutcome {pub(crate) fn event_dispatch_was_failed(self) -> bool {self.event_dispatch_failed}-- #[cfg(test)]- pub(crate) fn load_delay_was_settled(self) -> bool {- self.load_delay_settled- }}impl FrameDocumentModulepreloadTerminalWork {pub(crate) fn from_terminal_parts(- owner: FrameDocumentTaskOwner,realm_id: FrameRealmId,key: ModuleMapKey,client: FrameDocumentModulepreloadLinkClient,successful: bool,) -> Self {Self::new(- owner,+ client.owner(),realm_id,FrameDocumentModulepreloadTerminalPayload {key: Some(key),@@ -1030,12 +969,11 @@ impl FrameDocumentModulepreloadTerminalWork {}pub(crate) fn from_link_error_parts(- owner: FrameDocumentTaskOwner,realm_id: FrameRealmId,client: FrameDocumentModulepreloadLinkClient,) -> Self {Self::new(- owner,+ client.owner(),realm_id,FrameDocumentModulepreloadTerminalPayload {key: None,@@ -1081,17 +1019,14 @@ impl FrameDocumentModulepreloadTerminalWork {)}- pub(crate) fn into_event_action(- self,- binding: FrameDocumentModulepreloadEventBinding,- ) -> FrameDocumentModulepreloadEventAction {+ pub(crate) fn into_event_action(self) -> FrameDocumentModulepreloadEventAction {let (owner, realm_id, key, client, successful) = self.into_terminal_parts();- debug_assert_eq!(binding.client(), client);+ debug_assert_eq!(owner, client.owner());FrameDocumentModulepreloadEventAction {owner,realm_id,key,- binding,+ client,successful,}}@@ -1111,15 +1046,7 @@ impl FrameDocumentModulepreloadEventAction {}pub(crate) fn link_handle(&self) -> DomHandle {- self.binding.link_handle()- }-- pub(crate) fn binding(&self) -> FrameDocumentModulepreloadEventBinding {- self.binding- }-- pub(crate) fn load_delay_token(&self) -> Option<DocumentLoadDelayTokenId> {- self.binding.load_delay_token()+ self.client.link_handle()}pub(crate) fn successful(&self) -> bool {@@ -1141,11 +1068,6 @@ pub(crate) trait FrameDocumentModulepreloadEventActionHooks {action: &FrameDocumentModulepreloadEventAction,error: &str,);-- fn settle_modulepreload_event(- &mut self,- action: &FrameDocumentModulepreloadEventAction,- ) -> bool;}pub(crate) struct FrameDocumentModulepreloadEventActionRunner<Hooks> {@@ -1169,26 +1091,19 @@ where&mut self,action: FrameDocumentModulepreloadEventAction,) -> FrameDocumentModulepreloadTerminalOutcome {- let mut outcome = FrameDocumentModulepreloadTerminalOutcome::terminal_work_consumed();match self.hooks.dispatch_modulepreload_event(action.owner(),action.realm_id(),action.link_handle(),action.successful(),) {- Ok(()) => {- outcome.merge(FrameDocumentModulepreloadTerminalOutcome::event_dispatched());- }+ Ok(()) => FrameDocumentModulepreloadTerminalOutcome::event_dispatched(),Err(error) => {self.hooks.record_modulepreload_event_dispatch_failed(&action, &error);- outcome.merge(FrameDocumentModulepreloadTerminalOutcome::event_dispatch_failed());+ FrameDocumentModulepreloadTerminalOutcome::event_dispatch_failed()}}- if self.hooks.settle_modulepreload_event(&action) {- outcome.merge(FrameDocumentModulepreloadTerminalOutcome::load_delay_settled());- }- outcome}}@@ -1282,13 +1197,12 @@ impl FrameDocumentDynamicImportTerminalWork {impl FrameDocumentModulepreloadFetchTask {pub(crate) fn from_modulepreload_fetch_parts(- owner: FrameDocumentTaskOwner,realm_id: FrameRealmId,client: FrameDocumentModulepreloadLinkClient,request: NativeModuleSingleFetchRequest,) -> Self {Self::new(- owner,+ client.owner(),realm_id,FrameDocumentModulepreloadFetchPayload { client, request },)diff --git a/moli-renderer-v8/src/frame_owner_model/module_graph/document.rs b/moli-renderer-v8/src/frame_owner_model/module_graph/document.rsindex 0101af7cd..46382eb3e 100644--- a/moli-renderer-v8/src/frame_owner_model/module_graph/document.rs+++ b/moli-renderer-v8/src/frame_owner_model/module_graph/document.rs@@ -296,7 +296,6 @@ impl ChildDocumentModulatorEntry {"modulepreload terminal client must keep its accepted module key");FrameDocumentModulepreloadTerminalWork::from_terminal_parts(- owner,self.realm_id,key.clone(),link_clientdiff --git a/moli-renderer-v8/src/frame_owner_model/module_graph/tests.rs b/moli-renderer-v8/src/frame_owner_model/module_graph/tests.rsindex 49c2f6ae3..1872f90c2 100644--- a/moli-renderer-v8/src/frame_owner_model/module_graph/tests.rs+++ b/moli-renderer-v8/src/frame_owner_model/module_graph/tests.rs@@ -30,8 +30,7 @@ use crate::frame_owner_model::{FrameDocumentModuleTerminalBatch, FrameDocumentModuleTerminalQueueFollowup,FrameDocumentModuleTerminalWarning, FrameDocumentModuleTerminalWarningRecord,FrameDocumentModulepreloadEventAction, FrameDocumentModulepreloadEventActionHooks,- FrameDocumentModulepreloadEventActionRunner, FrameDocumentModulepreloadEventBinding,- FrameDocumentModulepreloadFetchCompletionAction,+ FrameDocumentModulepreloadEventActionRunner, FrameDocumentModulepreloadFetchCompletionAction,FrameDocumentModulepreloadFetchCompletionHooks,FrameDocumentModulepreloadFetchCompletionRunner, FrameDocumentModulepreloadFetchFinishResult,FrameDocumentModulepreloadFetchTask, FrameDocumentModulepreloadLinkClient,@@ -71,15 +70,11 @@ fn modulepreload_request(path: &str) -> NativeModuleSingleFetchRequest {)}-fn modulepreload_link_client(link_handle: DomHandle) -> FrameDocumentModulepreloadLinkClient {- FrameDocumentModulepreloadLinkClient::new(DomHandle::new(1), link_handle)-}--fn modulepreload_event_binding(link_handle: DomHandle) -> FrameDocumentModulepreloadEventBinding {- FrameDocumentModulepreloadEventBinding::new(- modulepreload_link_client(link_handle),- Some(crate::frame_owner_model::DocumentLoadDelayTokenId(91)),- )+fn modulepreload_link_client(+ owner: FrameDocumentTaskOwner,+ link_handle: DomHandle,+) -> FrameDocumentModulepreloadLinkClient {+ FrameDocumentModulepreloadLinkClient::new(DomHandle::new(1), owner, link_handle)}fn pending_dynamic_module_import() -> PendingDynamicModuleImport {diff --git a/moli-renderer-v8/src/frame_owner_model/module_graph/tests/document_modulator.rs b/moli-renderer-v8/src/frame_owner_model/module_graph/tests/document_modulator.rsindex 8f4a5fca6..30c0806a9 100644--- a/moli-renderer-v8/src/frame_owner_model/module_graph/tests/document_modulator.rs+++ b/moli-renderer-v8/src/frame_owner_model/module_graph/tests/document_modulator.rs@@ -12,9 +12,8 @@ fn modulepreload_start_action_reserves_fetch_in_modulator_store() {let request = modulepreload_request("modulepreload-start.js");let key = request.module_key().clone();let task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),request.clone(),);@@ -112,9 +111,8 @@ fn modulepreload_start_action_runner_schedules_fetch() {let link_handle = DomHandle::new(77);let request = modulepreload_request("modulepreload-runner-start.js");let task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),request,);let action = store.start_modulepreload_fetch_task(task);@@ -313,15 +311,13 @@ fn modulepreload_start_action_joins_fetching_entry_in_modulator_store() {let request = modulepreload_request("modulepreload-joined.js");let key = request.module_key().clone();let first_task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(first_link),+ modulepreload_link_client(owner, first_link),request.clone(),);let joined_task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(joined_link),+ modulepreload_link_client(owner, joined_link),request,);@@ -370,9 +366,8 @@ fn modulepreload_start_action_joins_terminal_entry_as_terminal_work() {"the terminal entry has no clients before the modulepreload task joins");let task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),request,);@@ -420,9 +415,8 @@ fn modulepreload_fetch_completion_settles_source_in_modulator_store() {let request = modulepreload_request("modulepreload-complete.js");let key = request.module_key().clone();let task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),request.clone(),);let FrameDocumentModulepreloadStartAction::ScheduleFetch { load_id, .. } =@@ -472,9 +466,8 @@ fn modulepreload_fetch_completion_marks_failure_in_modulator_store() {let request = modulepreload_request("modulepreload-failure.js");let key = request.module_key().clone();let task = FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,realm_id,- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),request,);let FrameDocumentModulepreloadStartAction::ScheduleFetch { load_id, .. } =@@ -532,7 +525,7 @@ fn restored_document_modulator_returns_modulepreload_terminal_work() {let link_client = crate::module_runtime::NativeModulepreloadLinkClient::new_for_frame_document(link_handle,key.clone(),- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),);document_modulator.add_modulepreload_link_client(key.clone(), link_client.clone());document_modulator.insert_fetched_source(@@ -631,9 +624,8 @@ fn modulepreload_link_error_event_builds_terminal_work_without_module_key() {let link_handle = DomHandle::new(77);let terminal_work = FrameDocumentModulepreloadTerminalWork::from_link_error_parts(- owner,realm_id,- modulepreload_link_client(link_handle),+ modulepreload_link_client(owner, link_handle),);assert_eq!(terminal_work.owner(), owner);diff --git a/moli-renderer-v8/src/frame_owner_model/module_graph/tests/followups.rs b/moli-renderer-v8/src/frame_owner_model/module_graph/tests/followups.rsindex 3dffc4414..9b0eab80e 100644--- a/moli-renderer-v8/src/frame_owner_model/module_graph/tests/followups.rs+++ b/moli-renderer-v8/src/frame_owner_model/module_graph/tests/followups.rs@@ -120,9 +120,8 @@ fn module_terminal_batch_keeps_modulepreload_terminals_out_of_event_task_lane()batch.push_modulepreload_terminal_work(FrameDocumentModulepreloadTerminalWork::from_link_error_parts(- task_owner,realm_id,- modulepreload_link_client(DomHandle::new(12)),+ modulepreload_link_client(task_owner, DomHandle::new(12)),),);@@ -139,11 +138,10 @@ fn modulepreload_event_action() -> FrameDocumentModulepreloadEventAction {FrameDocumentTaskOwner::new(FrameSchedulerLaneId(7), LocalWindowId(8), DocumentId(9));let realm_id = FrameRealmId(10);FrameDocumentModulepreloadTerminalWork::from_link_error_parts(- task_owner,realm_id,- modulepreload_link_client(DomHandle::new(12)),+ modulepreload_link_client(task_owner, DomHandle::new(12)),)- .into_event_action(modulepreload_event_binding(DomHandle::new(12)))+ .into_event_action()}#[derive(Default)]@@ -151,7 +149,6 @@ struct FakeModulepreloadEventActionHooks {fail_dispatch: bool,dispatch_calls: usize,failed_records: usize,- settled_events: usize,}impl FrameDocumentModulepreloadEventActionHooks for FakeModulepreloadEventActionHooks {@@ -177,14 +174,6 @@ impl FrameDocumentModulepreloadEventActionHooks for FakeModulepreloadEventAction) {self.failed_records += 1;}-- fn settle_modulepreload_event(- &mut self,- _action: &FrameDocumentModulepreloadEventAction,- ) -> bool {- self.settled_events += 1;- true- }}#[test]@@ -198,10 +187,8 @@ fn modulepreload_event_action_runner_reports_dispatched_event() {assert!(outcome.event_was_dispatched());assert!(!outcome.event_dispatch_was_failed());- assert!(outcome.load_delay_was_settled());assert_eq!(hooks.dispatch_calls, 1);assert_eq!(hooks.failed_records, 0);- assert_eq!(hooks.settled_events, 1);}#[test]@@ -217,9 +204,7 @@ fn modulepreload_event_action_runner_records_dispatch_failure() {assert!(outcome.event_dispatch_was_failed());assert!(!outcome.event_was_dispatched());- assert!(outcome.load_delay_was_settled());assert_eq!(hooks.dispatch_calls, 1);- assert_eq!(hooks.settled_events, 1);assert_eq!(hooks.failed_records, 1);}diff --git a/moli-renderer-v8/src/frame_owner_model/records.rs b/moli-renderer-v8/src/frame_owner_model/records.rsindex 9028e47ef..d84f61e5a 100644--- a/moli-renderer-v8/src/frame_owner_model/records.rs+++ b/moli-renderer-v8/src/frame_owner_model/records.rs@@ -1201,7 +1201,6 @@ pub(crate) enum DocumentLoadDelayReason {AsyncModuleScript,Image,Media,- Modulepreload,StyleLoadEvent,Navigation,}diff --git a/moli-renderer-v8/src/frame_owner_model/store.rs b/moli-renderer-v8/src/frame_owner_model/store.rsindex c5fff7dfc..e9f0ace6f 100644--- a/moli-renderer-v8/src/frame_owner_model/store.rs+++ b/moli-renderer-v8/src/frame_owner_model/store.rs@@ -2,20 +2,20 @@ use std::collections::{BTreeMap, HashMap, VecDeque};use super::ids::FrameOwnerIdAllocator;use super::lifecycle_tasks::{- ChildDocumentAsyncClassicScriptLoadDelay, FrameDocumentCompleteLifecycleAction,- FrameDocumentDomContentLoadedLifecycleAction, FrameDocumentImageLoadEventBinding,- FrameDocumentInteractiveLifecycleAction, FrameDocumentLifecycleAction,- FrameDocumentMediaLoadDelayBinding, MainDocumentCompleteLifecycleAction,- MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding,- MainDocumentInteractiveLifecycleAction, MainDocumentMediaLoadDelayBinding,- MainDocumentModulepreloadEventOwner, MainDocumentScriptLoadDelayKind,+ ChildDocumentAsyncClassicScriptLoadDelay, DocumentLinkEventOwner,+ FrameDocumentCompleteLifecycleAction, FrameDocumentDomContentLoadedLifecycleAction,+ FrameDocumentImageLoadEventBinding, FrameDocumentInteractiveLifecycleAction,+ FrameDocumentLifecycleAction, FrameDocumentMediaLoadDelayBinding,+ MainDocumentCompleteLifecycleAction, MainDocumentDomContentLoadedLifecycleAction,+ MainDocumentImageLoadDelayBinding, MainDocumentInteractiveLifecycleAction,+ MainDocumentMediaLoadDelayBinding, MainDocumentScriptLoadDelayKind,MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease,MainDocumentStyleLoadEventBinding, StylesheetSubresourceLoadDelayBinding,};use super::load_event_gate::DocumentLoadGateRelease;use super::module_clients::{FrameDocumentModuleClientReservation, FrameDocumentModuleFetchClientStart,- FrameDocumentModulepreloadEventBinding, FrameDocumentModulepreloadLinkClient,+ FrameDocumentModulepreloadLinkClient,};use super::navigation_tasks::{FrameLaneNavigationCommitTask, FrameNavigationCommitReservationResult,@@ -2689,9 +2689,9 @@ impl FrameOwnerStore {&self,owner: FrameDocumentTaskOwner,element: DomHandle,- ) -> Option<MainDocumentModulepreloadEventOwner> {+ ) -> Option<DocumentLinkEventOwner> {self.main_document_task_owner_is_current(owner)- .then(|| MainDocumentModulepreloadEventOwner::new(owner, element))+ .then(|| DocumentLinkEventOwner::new(owner, element))}pub(crate) fn main_style_load_event_is_current(@@ -3058,52 +3058,11 @@ impl FrameOwnerStore {}Some(FrameDocumentModulepreloadLinkClient::new(child_handle,- link_handle,- ))- }-- pub(crate) fn bind_current_child_modulepreload_event(- &mut self,- owner: FrameDocumentTaskOwner,- client: FrameDocumentModulepreloadLinkClient,- ) -> Option<FrameDocumentModulepreloadEventBinding> {- if !self.child_document_task_owner_is_current(client.child_handle(), owner) {- return None;- }- let load_delay_token = self.acquire_current_child_document_load_delay(- client.child_handle(),owner,- DocumentLoadDelayReason::Modulepreload,- );- if load_delay_token.is_none()- && !self- .documents- .get(&owner.document_id)- .filter(|document| document.local_window_id == owner.local_window_id)- .is_some_and(|document| document.lifecycle_progress.is_complete())- {- return None;- }- Some(FrameDocumentModulepreloadEventBinding::new(- client,- load_delay_token,+ link_handle,))}- pub(crate) fn settle_child_modulepreload_event(- &mut self,- owner: FrameDocumentTaskOwner,- binding: FrameDocumentModulepreloadEventBinding,- ) -> bool {- if !self.child_document_task_owner_is_current(binding.child_handle(), owner) {- return false;- }- let Some(token) = binding.load_delay_token() else {- return true;- };- self.release_document_load_delay(owner, token, DocumentLoadDelayReason::Modulepreload)- }-fn acquire_current_child_document_load_delay(&mut self,child_handle: DomHandle,diff --git a/moli-renderer-v8/src/frame_owner_model/store_tests.rs b/moli-renderer-v8/src/frame_owner_model/store_tests.rsindex c3464657e..6d2faa834 100644--- a/moli-renderer-v8/src/frame_owner_model/store_tests.rs+++ b/moli-renderer-v8/src/frame_owner_model/store_tests.rs@@ -4464,7 +4464,7 @@ fn child_media_load_delay_is_element_owned_and_cannot_settle_replacement() {}#[test]-fn child_modulepreload_terminal_event_delay_is_exact_and_replacement_owned() {+fn child_modulepreload_event_owner_is_exact_and_never_delays_complete() {let mut store = FrameOwnerStore::default();let child_handle = handle(368);store.ensure_child_frame(@@ -4488,9 +4488,18 @@ fn child_modulepreload_terminal_event_delay_is_exact_and_replacement_owned() {let owner = store.current_child_document_task_owner(child_handle).expect("child document should expose an owner");+ let load_delay_before_modulepreload =+ store.current_child_document_has_load_delay_tokens(child_handle, owner);let client = store.accept_current_child_modulepreload_link(child_handle, owner, handle(370)).expect("modulepreload acceptance should bind the current document");+ assert_eq!(client.owner(), owner);+ assert_eq!(client.link_handle(), handle(370));+ assert_eq!(+ store.current_child_document_has_load_delay_tokens(child_handle, owner),+ load_delay_before_modulepreload,+ "modulepreload admission must retain identity without changing the load gate"+ );let interactive = store.finish_current_child_document_parsing(child_handle, owner.document_owner())@@ -4500,46 +4509,20 @@ fn child_modulepreload_terminal_event_delay_is_exact_and_replacement_owned() {.prepare_current_child_document_domcontentloaded_transition(child_handle, owner).expect("modulepreload must not block DOMContentLoaded");assert!(store.apply_current_child_document_domcontentloaded_transition(domcontentloaded));- let preterminal_complete = store+ let complete = store.prepare_current_child_document_complete_transition(child_handle, owner).expect("fetching modulepreload must not block complete");- let binding = store- .bind_current_child_modulepreload_event(owner, client)- .expect("terminal modulepreload event should bind the current document");- assert!(- binding.load_delay_token().is_some(),- "a terminal modulepreload event queued before complete must own a load-delay token"- );- assert!(- !store.apply_current_child_document_complete_transition(preterminal_complete),- "binding the terminal event must invalidate a complete action prepared without it"- );assert!(- store- .prepare_current_child_document_complete_transition(child_handle, owner)- .is_none(),- "the exact terminal-event token must block complete"+ store.apply_current_child_document_complete_transition(complete),+ "a queued modulepreload terminal event must not invalidate child complete");-- assert!(store.settle_child_modulepreload_event(owner, binding));- assert!(- !store.settle_child_modulepreload_event(owner, binding),- "modulepreload event dispatch must consume its load-delay token exactly once"- );- let complete = store- .prepare_current_child_document_complete_transition(child_handle, owner)- .expect("modulepreload terminal should unblock complete");- assert!(store.apply_current_child_document_complete_transition(complete));let post_complete_client = store.accept_current_child_modulepreload_link(child_handle, owner, handle(371)).expect("a post-complete modulepreload still needs an exact event owner");- let post_complete_binding = store- .bind_current_child_modulepreload_event(owner, post_complete_client)- .expect("a post-complete modulepreload event still needs an exact document binding");assert_eq!(- post_complete_binding.load_delay_token(),- None,- "post-complete modulepreload event binding must not regress readyState"+ post_complete_client.owner(),+ owner,+ "post-complete modulepreload processing must retain the same exact Document");let transition = store@@ -4557,8 +4540,15 @@ fn child_modulepreload_terminal_event_delay_is_exact_and_replacement_owned() {.expect("replacement child document should commit");assert_eq!(transition.retired_owner(), Some(owner));assert!(- !store.settle_child_modulepreload_event(owner, post_complete_binding),- "a stale modulepreload event must not settle against the replacement document"+ !store.child_document_task_owner_is_current(client.child_handle(), client.owner()),+ "replacement must stale the old modulepreload identity without settlement"+ );+ assert!(+ !store.child_document_task_owner_is_current(+ post_complete_client.child_handle(),+ post_complete_client.owner(),+ ),+ "post-complete identity must not target the replacement Document");}diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_documents/lifecycle.rs b/moli-renderer-v8/src/native_bridge/context_host/child_documents/lifecycle.rsindex 4c8e50da9..22360a5e8 100644--- a/moli-renderer-v8/src/native_bridge/context_host/child_documents/lifecycle.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/child_documents/lifecycle.rs@@ -70,53 +70,31 @@ impl JsContextHost {.is_ok()}- pub(crate) fn bind_child_modulepreload_terminal_event(- &mut self,+ pub(crate) fn accept_child_modulepreload_terminal_event(+ &self,work: crate::frame_owner_model::FrameDocumentModulepreloadTerminalWork,) -> Option<crate::frame_owner_model::FrameDocumentModulepreloadEventAction> {- let Some(binding) = self+ if !self.frame_owner_store- .bind_current_child_modulepreload_event(work.owner(), work.client())- else {+ .child_document_task_owner_is_current(work.client().child_handle(), work.owner())+ {tracing::debug!(owner = ?work.owner(),realm_id = ?work.realm_id(),link_handle = ?work.link_handle(),successful = work.successful(),- "dropping stale child modulepreload terminal before event binding"+ "dropping stale child modulepreload terminal before event acceptance");return None;- };+ }tracing::debug!(owner = ?work.owner(),realm_id = ?work.realm_id(),link_handle = ?work.link_handle(),- load_delay_token = ?binding.load_delay_token(),successful = work.successful(),- "bound child modulepreload terminal to lifecycle-owned event action"+ "accepted child modulepreload terminal as a non-load-delaying event action");- Some(work.into_event_action(binding))- }-- pub(crate) fn settle_child_modulepreload_link_event(- &mut self,- owner: FrameDocumentTaskOwner,- binding: crate::frame_owner_model::FrameDocumentModulepreloadEventBinding,- queue_lifecycle_followup: bool,- ) -> bool {- if !self- .frame_owner_store- .settle_child_modulepreload_event(owner, binding)- {- return false;- }- if queue_lifecycle_followup && binding.load_delay_token().is_some() {- let _ = self.queue_child_document_complete_lifecycle_if_ready_for_owner(- binding.child_handle(),- owner,- );- }- true+ Some(work.into_event_action())}fn queue_current_child_document_image_load_events(diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frames/module_scripts.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frames/module_scripts.rsindex aa83cc885..1f8f867db 100644--- a/moli-renderer-v8/src/native_bridge/context_host/child_frames/module_scripts.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frames/module_scripts.rs@@ -416,11 +416,7 @@ impl JsContextHost {.is_none(){return self.queue_child_modulepreload_work_awaiting_realm(- FrameDocumentModulepreloadWorkAwaitingRealm::link_error(- owner,- expected_realm_id,- client,- ),+ FrameDocumentModulepreloadWorkAwaitingRealm::link_error(expected_realm_id, client),);}let Some(realm_id) = expected_realm_id else {@@ -433,7 +429,7 @@ impl JsContextHost {return false;};self.route_child_modulepreload_link_error(- FrameDocumentModulepreloadTerminalWork::from_link_error_parts(owner, realm_id, client),+ FrameDocumentModulepreloadTerminalWork::from_link_error_parts(realm_id, client),)}@@ -469,7 +465,6 @@ impl JsContextHost {{return self.queue_child_modulepreload_work_awaiting_realm(FrameDocumentModulepreloadWorkAwaitingRealm::fetch_start(- owner,expected_realm_id,client,request,@@ -488,7 +483,7 @@ impl JsContextHost {};self.route_child_modulepreload_start(FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner, realm_id, client, request,+ realm_id, client, request,),)}@@ -617,7 +612,7 @@ impl JsContextHost {&mut self,work: FrameDocumentModulepreloadTerminalWork,) -> bool {- let Some(action) = self.bind_child_modulepreload_terminal_event(work) else {+ let Some(action) = self.accept_child_modulepreload_terminal_event(work) else {return false;};self.route_child_modulepreload_event_action(action)diff --git a/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs b/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rsindex 4624e5f9d..c31e2c4a3 100644--- a/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs@@ -1,9 +1,9 @@use super::JsContextHost;use crate::frame_owner_model::{- DocumentLoadDelayTokenId, FrameDocumentTaskOwner, MainDocumentCompleteLifecycleAction,- MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding,- MainDocumentInteractiveLifecycleAction, MainDocumentLoadCompletionState,- MainDocumentMediaLoadDelayBinding, MainDocumentModulepreloadEventOwner,+ DocumentLinkEventOwner, DocumentLoadDelayTokenId, FrameDocumentTaskOwner,+ MainDocumentCompleteLifecycleAction, MainDocumentDomContentLoadedLifecycleAction,+ MainDocumentImageLoadDelayBinding, MainDocumentInteractiveLifecycleAction,+ MainDocumentLoadCompletionState, MainDocumentMediaLoadDelayBinding,MainDocumentScriptLoadDelayKind, MainDocumentScriptLoadDelayLease,MainDocumentScriptLoadDelayRelease, MainDocumentStyleLoadEventBinding,};@@ -193,7 +193,7 @@ impl JsContextHost {pub(crate) fn accept_current_main_modulepreload_event_owner(&self,element: crate::document_runtime::DomHandle,- ) -> Option<MainDocumentModulepreloadEventOwner> {+ ) -> Option<DocumentLinkEventOwner> {let owner = self.current_main_document_task_owner()?;self.frame_owner_store.accept_current_main_modulepreload_event_owner(owner, element)diff --git a/moli-renderer-v8/src/native_bridge/context_host/module_owner_tasks.rs b/moli-renderer-v8/src/native_bridge/context_host/module_owner_tasks.rsindex e0207fa8e..74b1a9ad4 100644--- a/moli-renderer-v8/src/native_bridge/context_host/module_owner_tasks.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/module_owner_tasks.rs@@ -90,7 +90,7 @@ impl JsContextHost {}pub(crate) fn route_child_modulepreload_event_action(- &mut self,+ &self,action: FrameDocumentModulepreloadEventAction,) -> bool {let sender = self.page_child_modulepreload_event_action_sender().clone();@@ -98,16 +98,11 @@ impl JsContextHost {Ok(()) => true,Err(closed) => {let action = closed.into_action();- let _ = self.settle_child_modulepreload_link_event(- action.owner(),- action.binding(),- false,- );tracing::debug!(owner = ?action.owner(),realm_id = ?action.realm_id(),link_handle = ?action.link_handle(),- "settled child modulepreload event after its stable Page route closed"+ "discarded child modulepreload event after its stable Page route closed");false}diff --git a/moli-renderer-v8/src/page_task_queue/child_modulepreload_event_action.rs b/moli-renderer-v8/src/page_task_queue/child_modulepreload_event_action.rsindex f16e8c219..003fbe74f 100644--- a/moli-renderer-v8/src/page_task_queue/child_modulepreload_event_action.rs+++ b/moli-renderer-v8/src/page_task_queue/child_modulepreload_event_action.rs@@ -211,7 +211,6 @@ pub(crate) enum PageChildModulepreloadEventActionTargetEffect {},DiscardedStaleOwner {current_owner: Option<RendererPageChildModulepreloadEventActionOwner>,- load_delay_settled: bool,},}diff --git a/moli-renderer-v8/src/page_task_queue/modulepreload_start.rs b/moli-renderer-v8/src/page_task_queue/modulepreload_start.rsindex 1e477a680..c952d445e 100644--- a/moli-renderer-v8/src/page_task_queue/modulepreload_start.rs+++ b/moli-renderer-v8/src/page_task_queue/modulepreload_start.rs@@ -286,10 +286,10 @@ mod tests {)).expect("modulepreload source URL");FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- owner,FrameRealmId(realm_id),FrameDocumentModulepreloadLinkClient::new(child_handle,+ owner,DomHandle::new(child_handle_raw + 100),),NativeModuleSingleFetchRequest::new(diff --git a/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rs b/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rsindex 8db05f462..c2bc150a3 100644--- a/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rs+++ b/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rs@@ -17,11 +17,10 @@ use crate::{FrameDocumentModuleClientEntryId, FrameDocumentModuleClientId,FrameDocumentModuleClientRegistration, FrameDocumentModuleClientReservation,FrameDocumentModuleDependencyFetchTask, FrameDocumentModuleFetchDisposition,- FrameDocumentModuleScriptTerminalBatchTask, FrameDocumentModulepreloadEventBinding,- FrameDocumentModulepreloadFetchTask, FrameDocumentModulepreloadLinkClient,- FrameDocumentModulepreloadTerminalWork, FrameDocumentStaticDependencyModuleClient,- FrameDocumentTaskOwner, FrameLaneNavigationCommitTask, FrameRealmId, FrameSchedulerLaneId,- LocalWindowId,+ FrameDocumentModuleScriptTerminalBatchTask, FrameDocumentModulepreloadFetchTask,+ FrameDocumentModulepreloadLinkClient, FrameDocumentModulepreloadTerminalWork,+ FrameDocumentStaticDependencyModuleClient, FrameDocumentTaskOwner,+ FrameLaneNavigationCommitTask, FrameRealmId, FrameSchedulerLaneId, LocalWindowId,},module_runtime::{ModuleEntryId, ModuleFetchMetadata, ModuleImportPhase, ModuleKind, ModuleMapKey,@@ -1651,15 +1650,16 @@ fn window_execution_context(seed: u64) -> WindowExecutionContextIdentity {fn modulepreload_task(sequence: u64) -> FrameDocumentModulepreloadFetchTask {let child_handle = DomHandle::new(sequence as usize + 100);+ let owner = task_owner(sequence + 10);let source_url = Url::parse(&format!("https://page-source-conformance.test/modulepreload-{sequence}.mjs")).expect("modulepreload conformance URL");FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- task_owner(sequence + 10),FrameRealmId(sequence as i64 + 20),FrameDocumentModulepreloadLinkClient::new(child_handle,+ owner,DomHandle::new(sequence as usize + 200),),NativeModuleSingleFetchRequest::new(@@ -1741,16 +1741,17 @@ fn module_dependency_fetch_task(fn modulepreload_event_action(sequence: u64,) -> crate::frame_owner_model::FrameDocumentModulepreloadEventAction {+ let owner = task_owner(sequence + 60);let client = FrameDocumentModulepreloadLinkClient::new(DomHandle::new(sequence as usize + 400),+ owner,DomHandle::new(sequence as usize + 500),);FrameDocumentModulepreloadTerminalWork::from_link_error_parts(- task_owner(sequence + 60),FrameRealmId(sequence as i64 + 70),client,)- .into_event_action(FrameDocumentModulepreloadEventBinding::new(client, None))+ .into_event_action()}fn dynamic_import_action(sequence: u64) -> FrameDocumentDynamicImportTerminalPreparedAction {diff --git a/moli-renderer-v8/src/runtime/page_vm/page_child_modulepreload_event_action.rs b/moli-renderer-v8/src/runtime/page_vm/page_child_modulepreload_event_action.rsindex d28cdff24..e66b9278d 100644--- a/moli-renderer-v8/src/runtime/page_vm/page_child_modulepreload_event_action.rs+++ b/moli-renderer-v8/src/runtime/page_vm/page_child_modulepreload_event_action.rs@@ -103,23 +103,13 @@ impl PageVm {);PageChildModulepreloadEventActionTargetEffect::AppliedToCurrentOwner { outcome }} else {- let load_delay_settled =- if owner.root_document() == self.document_lifecycle.identity().document {- self.vm_mut()- .settle_stale_child_modulepreload_event_action(task.into_action())- } else {- false- };+ drop(task);tracing::debug!(?owner,?current_owner,- load_delay_settled,"discarded stale exact-owner child modulepreload event action");- PageChildModulepreloadEventActionTargetEffect::DiscardedStaleOwner {- current_owner,- load_delay_settled,- }+ PageChildModulepreloadEventActionTargetEffect::DiscardedStaleOwner { current_owner }};let action = PageChildModulepreloadEventActionTurnAction {owner,diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/child_modulepreload_event_action.rs b/moli-renderer-v8/src/runtime/page_vm/tests/child_modulepreload_event_action.rsindex 96a84ebdb..4dba4a216 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/child_modulepreload_event_action.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/child_modulepreload_event_action.rs@@ -239,7 +239,7 @@ document}#[tokio::test(flavor = "current_thread")]-async fn replaced_realm_discards_real_modulepreload_event_and_settles_its_exact_document() {+async fn replaced_realm_discards_real_modulepreload_event_without_lifecycle_side_effects() {run_page_vm_async_test(async move {let loader =crate::network::ResourceRequestClient::new(&FetchConfig::default()).expect("loader");@@ -290,9 +290,8 @@ async fn replaced_realm_discards_real_modulepreload_event_and_settles_its_exact_outcome.action.target_effect,PageChildModulepreloadEventActionTargetEffect::DiscardedStaleOwner {current_owner: None,- load_delay_settled: true,},- "a stale realm must not dispatch, but its still-current Document delay must settle"+ "a stale realm must discard its identity-only modulepreload event");assert!(matches!(outcome.action.into_page_task_completion(),@@ -386,7 +385,6 @@ fn page_vm_replacement_rejects_naturally_colliding_modulepreload_event_owner() {stale.action.target_effect,PageChildModulepreloadEventActionTargetEffect::DiscardedStaleOwner {current_owner: None,- load_delay_settled: false,},"an old root token must prevent all replacement-Document application");diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/mod.rs b/moli-renderer-v8/src/runtime/page_vm/tests/mod.rsindex 8fcc76a10..8c25bcc76 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/mod.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/mod.rs@@ -1525,10 +1525,10 @@ fn test_child_modulepreload_start_task_for_target(let source_url = Url::parse(&format!("https://{label}.test/modulepreload.js")).expect("modulepreload start URL");FrameDocumentModulepreloadFetchTask::from_modulepreload_fetch_parts(- target.task_owner(),target.realm_id(),FrameDocumentModulepreloadLinkClient::new(target.child_handle(),+ target.task_owner(),crate::dom::native::NativeNodeId::new(997),),NativeModuleSingleFetchRequest::new(@@ -1877,12 +1877,6 @@ enum ChildModulepreloadStartupTurn {ChildSemanticTurn(ChildFrameSemanticTurnKind),}-#[derive(Clone, Copy, Debug, Eq, PartialEq)]-enum ChildModulepreloadSemanticTurn {- TypedEventAction,- ChildSemanticTurn(ChildFrameSemanticTurnKind),-}-async fn run_expected_child_modulepreload_event_action_for_test(page_vm: &mut PageVm,loader: &crate::network::ResourceRequestClient,@@ -8691,13 +8685,19 @@ parent.__childModuleDependencyFailureEvents.push("root:" + depValue);}#[tokio::test]-async fn page_vm_child_modulepreload_terminal_event_delays_complete_until_event_turn() {+async fn page_vm_child_modulepreload_terminal_event_does_not_delay_complete() {run_page_vm_async_test(async move {let loader = crate::network::ResourceRequestClient::new(&FetchConfig::default()).expect("loader");let page_vm = test_page_vm();let local_executor = page_vm.local_executor.clone();- let turns = local_executor+ let (+ lifecycle_turns,+ events_before_preload_event,+ ready_state_before_preload_event,+ events_after_preload_event,+ ready_state_after_preload_event,+ ) = local_executor.run(async move {let mut page_vm = page_vm;page_vm.vm_mut().eval(@@ -8723,100 +8723,77 @@ async fn page_vm_child_modulepreload_terminal_event_delays_complete_until_event_"#,)?;- let mut turns = Vec::new();- loop {- let turn = if page_vm+ let mut lifecycle_turns = Vec::new();+ while let Some(source) = page_vm+ .run_next_child_frame_task_source_for_semantic_test()+ .await+ {+ lifecycle_turns.push(source);+ }++ let events_before_preload_event = page_vm+ .vm_mut()+ .eval("__childModulepreloadTerminalEvents.join('|')")?;+ let ready_state_before_preload_event = page_vm.vm_mut().eval(+ "document.querySelector('iframe').contentDocument?.readyState || 'missing'",+ )?;++ assert!(+ page_vm.run_exact_selected_page_task_for_test(PageSelectedTaskTestSelector::ChildModulepreloadEventAction,&loader,)- .await?- {- ChildModulepreloadSemanticTurn::TypedEventAction- } else if let Some(source) = page_vm- .run_next_child_frame_task_source_for_semantic_test()- .await- {- ChildModulepreloadSemanticTurn::ChildSemanticTurn(source)- } else {- break;- };- let events = page_vm- .vm_mut()- .eval("__childModulepreloadTerminalEvents.join('|')")?;- let ready_state = page_vm.vm_mut().eval(- "document.querySelector('iframe').contentDocument?.readyState || 'missing'",- )?;- turns.push((turn, events, ready_state));- }- Ok::<_, anyhow::Error>(turns)+ .await?,+ "the deliberately withheld modulepreload error action must remain queued"+ );+ let events_after_preload_event = page_vm+ .vm_mut()+ .eval("__childModulepreloadTerminalEvents.join('|')")?;+ let ready_state_after_preload_event = page_vm.vm_mut().eval(+ "document.querySelector('iframe').contentDocument?.readyState || 'missing'",+ )?;++ Ok::<_, anyhow::Error>((+ lifecycle_turns,+ events_before_preload_event,+ ready_state_before_preload_event,+ events_after_preload_event,+ ready_state_after_preload_event,+ ))}).await.expect("terminal child modulepreload lifecycle test should run");- let (event_turn_index, event_turn) = turns- .iter()- .enumerate()- .find(|(_, (_, events, _))| events.contains("preload-error"))- .expect("invalid modulepreload should dispatch an error event");- assert_eq!(- event_turn.0,- ChildModulepreloadSemanticTurn::TypedEventAction- );assert!(- turns[..event_turn_index].iter().all(|(turn, _, _)| {- !matches!(- turn,- ChildModulepreloadSemanticTurn::ChildSemanticTurn(- ChildFrameSemanticTurnKind::DocumentLifecycle- | ChildFrameSemanticTurnKind::HostLoad- )- )- }),- "the modulepreload terminal event must settle its load delay before child lifecycle or HostLoad delivery: {turns:?}"+ lifecycle_turns+ .iter()+ .filter(|source| **source == ChildFrameSemanticTurnKind::DocumentLifecycle)+ .count()+ >= 3,+ "interactive, DOMContentLoaded, and complete must advance while the terminal link event remains queued: {lifecycle_turns:?}");assert!(- !event_turn.1.contains("frame-load"),- "modulepreload event dispatch must not inline complete or iframe load"+ lifecycle_turns.contains(&ChildFrameSemanticTurnKind::HostLoad),+ "iframe load must remain independently runnable while the terminal link event is withheld: {lifecycle_turns:?}");-- let (complete_turn_index, complete_turn) = turns- .iter()- .enumerate()- .skip(event_turn_index + 1)- .find(|(_, (_, _, ready_state))| ready_state == "complete")- .expect("terminal event release should queue document complete");- assert!(complete_turn_index > event_turn_index);- assert_eq!(- complete_turn.0,- ChildModulepreloadSemanticTurn::ChildSemanticTurn(- ChildFrameSemanticTurnKind::DocumentLifecycle- )+ assert_eq!(+ events_before_preload_event,+ "before|after|dcl:interactive|frame-load",+ "child complete and iframe load must not wait for the queued modulepreload error");- assert!(- !complete_turn.1.contains("frame-load"),- "complete transition must not inline iframe load"+ assert_eq!(+ ready_state_before_preload_event, "complete",+ "a terminal modulepreload event must not hold the child Document load gate");-- let (host_load_turn_index, host_load_turn) = turns- .iter()- .enumerate()- .find(|(_, (_, events, _))| events.contains("frame-load"))- .expect("completed child document should dispatch iframe load");- assert!(host_load_turn_index > complete_turn_index);assert_eq!(- host_load_turn.0,- ChildModulepreloadSemanticTurn::ChildSemanticTurn(ChildFrameSemanticTurnKind::HostLoad)+ events_after_preload_event,+ "before|after|dcl:interactive|frame-load|preload-error",+ "the independently queued modulepreload event must still dispatch afterward");- for required in ["before", "after", "dcl:interactive", "preload-error"] {- assert!(- host_load_turn.1.contains(required),- "HostLoad must observe every parser/lifecycle/modulepreload predecessor: {turns:?}"- );- }- assert!(- host_load_turn.1.ends_with("frame-load"),- "iframe load must remain the final observable delivery regardless of cross-source DCL/modulepreload arbitration: {turns:?}"+ assert_eq!(+ ready_state_after_preload_event, "complete",+ "post-complete modulepreload dispatch must not regress readyState");}).await;diff --git a/moli-renderer-v8/src/script_vm/child_document_modulator.rs b/moli-renderer-v8/src/script_vm/child_document_modulator.rsindex 69922c31b..45d60bae7 100644--- a/moli-renderer-v8/src/script_vm/child_document_modulator.rs+++ b/moli-renderer-v8/src/script_vm/child_document_modulator.rs@@ -348,8 +348,8 @@ impl ScriptVm {) -> FrameDocumentModuleTerminalQueueFollowup {let mut promoted = false;for work in works {- let mut host = self._context_host.borrow_mut();- let Some(action) = host.bind_child_modulepreload_terminal_event(work) else {+ let host = self._context_host.borrow();+ let Some(action) = host.accept_child_modulepreload_terminal_event(work) else {continue;};promoted |= host.route_child_modulepreload_event_action(action);diff --git a/moli-renderer-v8/src/script_vm/child_modulepreload_event_action.rs b/moli-renderer-v8/src/script_vm/child_modulepreload_event_action.rsindex 8bcc3eb8f..8a5db53d8 100644--- a/moli-renderer-v8/src/script_vm/child_modulepreload_event_action.rs+++ b/moli-renderer-v8/src/script_vm/child_modulepreload_event_action.rs@@ -38,15 +38,6 @@ impl ScriptVm {.run_event_action(authorization.into_action())}- pub(crate) fn settle_stale_child_modulepreload_event_action(- &mut self,- action: FrameDocumentModulepreloadEventAction,- ) -> bool {- self._context_host- .borrow_mut()- .settle_child_modulepreload_link_event(action.owner(), action.binding(), true)- }-#[cfg(test)]/// Executes only the typed modulepreload event body.///@@ -83,8 +74,6 @@ impl ScriptVm {action,),);- } else {- let _ = self.settle_stale_child_modulepreload_event_action(action);}true}@@ -124,33 +113,4 @@ impl FrameDocumentModulepreloadEventActionHooks for ScriptVmChildModulepreloadEv"child modulepreload event action dispatch failed");}-- fn settle_modulepreload_event(- &mut self,- action: &FrameDocumentModulepreloadEventAction,- ) -> bool {- let settled = self- .vm- ._context_host- .borrow_mut()- .settle_child_modulepreload_link_event(action.owner(), action.binding(), true);- if settled {- tracing::debug!(- owner = ?action.owner(),- realm_id = ?action.realm_id(),- link_handle = ?action.link_handle(),- load_delay_token = ?action.load_delay_token(),- "settled child modulepreload lifecycle delay after link event terminal"- );- } else {- tracing::debug!(- owner = ?action.owner(),- realm_id = ?action.realm_id(),- link_handle = ?action.link_handle(),- load_delay_token = ?action.load_delay_token(),- "child modulepreload lifecycle delay was already retired or stale"- );- }- settled- }}diff --git a/moli-renderer-v8/src/stylesheet_runtime/connected.rs b/moli-renderer-v8/src/stylesheet_runtime/connected.rsindex 6476ea637..0e75494d0 100644--- a/moli-renderer-v8/src/stylesheet_runtime/connected.rs+++ b/moli-renderer-v8/src/stylesheet_runtime/connected.rs@@ -577,7 +577,7 @@ impl DocumentRuntime {}ConnectedStyleLoadEventPlan::NonBlockingModulepreload { element } => {ConnectedStyleLoadEventAdmission::NonBlockingModulepreload(- crate::frame_owner_model::MainDocumentModulepreloadEventOwner::unowned_for_document_runtime_test(+ crate::frame_owner_model::DocumentLinkEventOwner::unowned_for_document_runtime_test(element,),)diff --git a/moli-renderer-v8/src/stylesheet_runtime/load.rs b/moli-renderer-v8/src/stylesheet_runtime/load.rsindex 29ce8d984..bb996d693 100644--- a/moli-renderer-v8/src/stylesheet_runtime/load.rs+++ b/moli-renderer-v8/src/stylesheet_runtime/load.rs@@ -1,8 +1,6 @@use std::sync::{Arc, OnceLock};-use crate::frame_owner_model::{- MainDocumentModulepreloadEventOwner, MainDocumentStyleLoadEventBinding,-};+use crate::frame_owner_model::{DocumentLinkEventOwner, MainDocumentStyleLoadEventBinding};use crate::module_runtime::{NativeModulepreloadFetchStart, NativeModulepreloadLinkClient};use crate::style_engine::OwnerStyleSheetSource;use crate::stylesheet_blocking::{@@ -220,7 +218,7 @@ impl ConnectedStyleLoadEventPlan {#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum ConnectedStyleLoadEventAdmission {LoadDelaying(MainDocumentStyleLoadEventBinding),- NonBlockingModulepreload(MainDocumentModulepreloadEventOwner),+ NonBlockingModulepreload(DocumentLinkEventOwner),}impl ConnectedStyleLoadEventAdmission {