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 modulepreload from delaying load
ldm08d82acf95397
diff --git a/moli-renderer-v8/src/document_module_graph/client.rs b/moli-renderer-v8/src/document_module_graph/client.rsindex a61837ef2..27e6c2432 100644--- a/moli-renderer-v8/src/document_module_graph/client.rs+++ b/moli-renderer-v8/src/document_module_graph/client.rs@@ -3,7 +3,7 @@ use std::sync::Arc;use crate::dom::native::NativeNodeId;use crate::frame_owner_model::{- FrameDocumentModulepreloadLinkClient, MainDocumentStyleLoadEventBinding,+ FrameDocumentModulepreloadLinkClient, MainDocumentModulepreloadEventOwner,};use super::ModuleMapKey;@@ -16,25 +16,30 @@ use super::ModuleMapKey;pub(crate) struct NativeModulepreloadLinkClient {owner: NativeNodeId,key: ModuleMapKey,- load_event_binding: Option<MainDocumentStyleLoadEventBinding>,+ main_document_event_owner: Option<MainDocumentModulepreloadEventOwner>,frame_document_client: Option<FrameDocumentModulepreloadLinkClient>,}impl NativeModulepreloadLinkClient {#[cfg(test)]pub(crate) fn new(owner: NativeNodeId, key: ModuleMapKey) -> Arc<Self> {- Self::new_with_load_event_binding(owner, key, None)+ Arc::new(Self {+ owner,+ key,+ main_document_event_owner: None,+ frame_document_client: None,+ })}- pub(crate) fn new_with_load_event_binding(+ pub(crate) fn new_with_main_document_event_owner(owner: NativeNodeId,key: ModuleMapKey,- load_event_binding: Option<MainDocumentStyleLoadEventBinding>,+ main_document_event_owner: MainDocumentModulepreloadEventOwner,) -> Arc<Self> {Arc::new(Self {owner,key,- load_event_binding,+ main_document_event_owner: Some(main_document_event_owner),frame_document_client: None,})}@@ -47,7 +52,7 @@ impl NativeModulepreloadLinkClient {Arc::new(Self {owner,key,- load_event_binding: None,+ main_document_event_owner: None,frame_document_client: Some(frame_document_client),})}@@ -60,8 +65,8 @@ impl NativeModulepreloadLinkClient {&self.key}- pub(crate) fn load_event_binding(&self) -> Option<MainDocumentStyleLoadEventBinding> {- self.load_event_binding+ pub(crate) fn main_document_event_owner(&self) -> Option<MainDocumentModulepreloadEventOwner> {+ self.main_document_event_owner}pub(crate) fn frame_document_client(&self) -> Option<FrameDocumentModulepreloadLinkClient> {diff --git a/moli-renderer-v8/src/document_runtime.rs b/moli-renderer-v8/src/document_runtime.rsindex 1d18b3030..6fde12b31 100644--- a/moli-renderer-v8/src/document_runtime.rs+++ b/moli-renderer-v8/src/document_runtime.rs@@ -100,8 +100,10 @@ use stylesheet_runtime::{StylesheetOwnerCspDisposition, StylesheetOwnerRuntimeStates,};pub(crate) use stylesheet_runtime::{- ConnectedStyleEventElementKind, ConnectedStyleLoadPrimeResult, InstallLinkedStylesheet,- OwnerlessStylesheetAdmissionError, PreparedLinkedStylesheetResource, ReadyConnectedStyleLoad,+ ConnectedStyleEventElementKind, ConnectedStyleLoadEventAdmission, ConnectedStyleLoadEventPlan,+ ConnectedStyleLoadPrimeResult, InstallLinkedStylesheet, NativeModulepreloadLinkFetchOutcome,+ OwnerlessStylesheetAdmissionError, PendingNativeModulepreloadLinkEvent,+ PreparedConnectedStyleLoad, PreparedLinkedStylesheetResource, ReadyConnectedStyleLoad,StylesheetLinkClientTerminal,};@@ -2613,7 +2615,7 @@ mod tests {.parent_node(link).expect("link should have a parent");assert!(runtime.dom_host_mut().remove_child(parent, link));- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));runtime.stylesheet_lifecycle@@ -2658,7 +2660,7 @@ mod tests {.active_stylesheet_link_client_for_test(link).expect("active stylesheet load");assert!(runtime.dom_host_mut().set_attribute(link, "disabled", ""));- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));runtime.queue_connected_style_loads(link);runtime.prime_document_lifecycle_processing();assert!(@@ -2710,7 +2712,7 @@ mod tests {.active_stylesheet_link_client_for_test(link).expect("first A processing load");- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));assert!(runtime.dom_host_mut().set_attribute(link, "href", "/b.css"));runtime.queue_connected_style_loads(link);runtime.prime_document_lifecycle_processing();@@ -2718,7 +2720,7 @@ mod tests {.active_stylesheet_link_client_for_test(link).expect("B processing load");- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));assert!(runtime.dom_host_mut().set_attribute(link, "href", "/a.css"));runtime.queue_connected_style_loads(link);runtime.prime_document_lifecycle_processing();@@ -2771,7 +2773,7 @@ mod tests {Some("sha256-first"));- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));assert!(runtime.dom_host_mut()@@ -3521,14 +3523,14 @@ mod tests {}],});- runtime.invalidate_style_related_state(std::ptr::null_mut(), owner);+ drop(runtime.invalidate_style_related_state(owner));runtime.stylesheet_lifecycle.owner_states.install_pending_operation(operation_for("@import url('/middle.css'); /* B */ @import url('/shared.css');",));- runtime.invalidate_style_related_state(std::ptr::null_mut(), owner);+ drop(runtime.invalidate_style_related_state(owner));let current_a = operation_for("@import url('/shared.css'); /* current A */");runtime.stylesheet_lifecyclediff --git a/moli-renderer-v8/src/document_runtime/mutation_commands.rs b/moli-renderer-v8/src/document_runtime/mutation_commands.rsindex 062159371..e894af850 100644--- a/moli-renderer-v8/src/document_runtime/mutation_commands.rs+++ b/moli-renderer-v8/src/document_runtime/mutation_commands.rs@@ -1808,7 +1808,50 @@ pub(super) fn finish_runtime_mutation_effects(}runtime.apply_pending_stylesheet_source_css_projections(scope, host_ptr);if changed {- runtime.apply_stylesheet_owner_runtime_changes(host_ptr, &stylesheet_owner_changes);+ let prepared_owner_changes =+ runtime.prepare_stylesheet_owner_runtime_changes(&stylesheet_owner_changes);+ let (canceled_load_event_bindings, prepared_owner_changes) =+ prepared_owner_changes.into_parts();+ for binding in canceled_load_event_bindings {+ let settled = unsafe { &mut *host_ptr }.settle_main_style_load_event(binding);+ tracing::debug!(+ owner = ?binding.owner(),+ element = ?binding.element(),+ load_delay_token = ?binding.load_delay_token(),+ settled,+ "settled invalidated connected-style lease at mutation commit"+ );+ }+ for prepared_owner_change in prepared_owner_changes {+ let owner = prepared_owner_change.owner();+ if let Some(url) = prepared_owner_change.cached_linked_stylesheet_url() {+ let _ = unsafe { &mut *host_ptr }+ .install_cached_linked_stylesheet_for_owner(owner, url);+ }+ let inline_source = unsafe { &*host_ptr }.owner_style_sheet_processing_source(owner);+ let prepared_loads = runtime.prepare_connected_style_loads(owner, false);+ for prepared_load in prepared_loads {+ // A native DOM callback already owns this exact live host.+ // Commit touches only FrameOwnerStore and never dereferences+ // the runtime pointer; apply resumes after that borrow ends.+ let event_admission = unsafe { &mut *host_ptr }+ .commit_connected_style_load_event_plan(prepared_load.event_plan());+ let Some(event_admission) = event_admission else {+ tracing::debug!(+ owner = ?prepared_load.owner(),+ "discarded mutation connected-style plan rejected by the current main Document"+ );+ continue;+ };+ debug_assert_eq!(prepared_load.owner(), owner);+ runtime.apply_prepared_connected_style_load(+ prepared_load,+ inline_source.clone(),+ event_admission,+ host_ptr,+ );+ }+ }crate::native_bridge::document::apply_stylesheet_owner_css_projections(scope,unsafe { &*host_ptr },diff --git a/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rs b/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rsindex 7b62695ef..5c7a68c74 100644--- a/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rs+++ b/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rs@@ -460,47 +460,74 @@ impl DocumentRuntime {request: NativeModuleSingleFetchRequest,) -> std::result::Result<NativeModulepreloadFetchStart, ModuleLoadError> {self.fetch_single_native_module_for_modulepreload_client(request, None)+ .map(|(fetch_start, _)| fetch_start)}pub(crate) fn fetch_single_native_module_for_modulepreload_link(&mut self,request: NativeModuleSingleFetchRequest,link_client: std::sync::Arc<crate::module_runtime::NativeModulepreloadLinkClient>,- ) -> std::result::Result<NativeModulepreloadFetchStart, ModuleLoadError> {+ ) -> std::result::Result<NativeModulepreloadLinkFetchOutcome, ModuleLoadError> {self.fetch_single_native_module_for_modulepreload_client(request, Some(link_client))+ .map(|(fetch_start, pending_event)| {+ NativeModulepreloadLinkFetchOutcome::new(fetch_start, pending_event)+ })}fn fetch_single_native_module_for_modulepreload_client(&mut self,request: NativeModuleSingleFetchRequest,link_client: Option<std::sync::Arc<crate::module_runtime::NativeModulepreloadLinkClient>>,- ) -> std::result::Result<NativeModulepreloadFetchStart, ModuleLoadError> {+ ) -> std::result::Result<+ (+ NativeModulepreloadFetchStart,+ Option<PendingNativeModulepreloadLinkEvent>,+ ),+ ModuleLoadError,+ > {let key = request.module_key().clone();match self.start_or_join_native_module_fetch(key.clone()) {ModuleMapFetchDisposition::StartedFetch(_) => {if let Some(client) = link_client {self.suspend_native_modulepreload_link_clients(key, vec![client]);}- Ok(NativeModulepreloadFetchStart::Started(Box::new(request)))+ Ok((+ NativeModulepreloadFetchStart::Started(Box::new(request)),+ None,+ ))}ModuleMapFetchDisposition::JoinedFetching(_) => {if let Some(client) = link_client {self.suspend_native_modulepreload_link_clients(key, vec![client]);}- Ok(NativeModulepreloadFetchStart::Joined)+ Ok((NativeModulepreloadFetchStart::Joined, None))}ModuleMapFetchDisposition::AlreadyFetched(_)| ModuleMapFetchDisposition::AlreadyCompiled(_) => {- if let Some(client) = link_client {- self.complete_native_modulepreload_link_clients(&key, vec![client], true);- }- Ok(NativeModulepreloadFetchStart::AlreadyComplete)+ let pending_event = link_client.and_then(|client| {+ self.accept_native_modulepreload_link_client_terminals(&key, vec![client], true)+ .into_iter()+ .next()+ });+ Ok((+ NativeModulepreloadFetchStart::AlreadyComplete,+ pending_event,+ ))}ModuleMapFetchDisposition::AlreadyFailed(_) => {- if let Some(client) = link_client {- self.complete_native_modulepreload_link_clients(&key, vec![client], false);- }- Ok(NativeModulepreloadFetchStart::AlreadyComplete)+ let pending_event = link_client.and_then(|client| {+ self.accept_native_modulepreload_link_client_terminals(+ &key,+ vec![client],+ false,+ )+ .into_iter()+ .next()+ });+ Ok((+ NativeModulepreloadFetchStart::AlreadyComplete,+ pending_event,+ ))}}}diff --git a/moli-renderer-v8/src/frame_owner_model.rs b/moli-renderer-v8/src/frame_owner_model.rsindex c7eb2a101..0ae10cc88 100644--- a/moli-renderer-v8/src/frame_owner_model.rs+++ b/moli-renderer-v8/src/frame_owner_model.rs@@ -76,9 +76,9 @@ pub(crate) use lifecycle_tasks::{FrameDocumentUnloadLifecycleAction, MainDocumentCompleteLifecycleAction,MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding,MainDocumentInteractiveLifecycleAction, MainDocumentMediaLoadDelayBinding,- MainDocumentScriptLoadDelayKind, MainDocumentScriptLoadDelayLease,- MainDocumentScriptLoadDelayRelease, MainDocumentStyleLoadEventBinding,- StylesheetSubresourceLoadDelayBinding,+ MainDocumentModulepreloadEventOwner, MainDocumentScriptLoadDelayKind,+ MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease,+ MainDocumentStyleLoadEventBinding, StylesheetSubresourceLoadDelayBinding,};pub(crate) use load_delivery_tasks::{FrameDocumentLoadDeliveryAction, FrameDocumentLoadDeliveryAdmission,diff --git a/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs b/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rsindex 4c41310d7..55a3d4c01 100644--- a/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs+++ b/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs@@ -82,8 +82,11 @@ impl MainDocumentScriptLoadDelayLease {}/// Exact main-document ownership for a connected `<style>`/`<link>` load or-/// error event. The token remains live across network completion and event-/// dispatch so document `load` cannot overtake the element event.+/// error event.+///+/// Stylesheet processing may retain the token across its network load.+/// `modulepreload` never uses this type; it retains only+/// [`MainDocumentModulepreloadEventOwner`].#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) struct MainDocumentStyleLoadEventBinding {owner: FrameDocumentTaskOwner,@@ -132,6 +135,45 @@ impl MainDocumentStyleLoadEventBinding {}}+/// Exact Document and element identity retained while a non-blocking+/// `modulepreload` fetch is in flight.+///+/// This deliberately carries no load-delay token and remains the complete+/// lifecycle identity through terminal acceptance and event publication.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) struct MainDocumentModulepreloadEventOwner {+ owner: FrameDocumentTaskOwner,+ element: DomHandle,+}++impl MainDocumentModulepreloadEventOwner {+ pub(super) fn new(owner: FrameDocumentTaskOwner, element: DomHandle) -> Self {+ Self { owner, element }+ }++ pub(crate) fn owner(self) -> FrameDocumentTaskOwner {+ self.owner+ }++ pub(crate) fn element(self) -> DomHandle {+ self.element+ }++ #[cfg(test)]+ pub(crate) fn unowned_for_document_runtime_test(element: DomHandle) -> Self {+ use super::records::{DocumentId, FrameSchedulerLaneId, LocalWindowId};++ Self::new(+ FrameDocumentTaskOwner::new(+ FrameSchedulerLaneId(u64::MAX),+ LocalWindowId(u64::MAX),+ DocumentId(u64::MAX),+ ),+ element,+ )+ }+}+/// Exact document ownership for one load-blocking resource discovered while/// installing a stylesheet. Unlike a style element event, this binding ends at/// the image/font network terminal and therefore needs no DOM element target.diff --git a/moli-renderer-v8/src/frame_owner_model/store.rs b/moli-renderer-v8/src/frame_owner_model/store.rsindex d3e13ae0f..c5fff7dfc 100644--- a/moli-renderer-v8/src/frame_owner_model/store.rs+++ b/moli-renderer-v8/src/frame_owner_model/store.rs@@ -8,9 +8,9 @@ use super::lifecycle_tasks::{FrameDocumentMediaLoadDelayBinding, MainDocumentCompleteLifecycleAction,MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding,MainDocumentInteractiveLifecycleAction, MainDocumentMediaLoadDelayBinding,- MainDocumentScriptLoadDelayKind, MainDocumentScriptLoadDelayLease,- MainDocumentScriptLoadDelayRelease, MainDocumentStyleLoadEventBinding,- StylesheetSubresourceLoadDelayBinding,+ MainDocumentModulepreloadEventOwner, MainDocumentScriptLoadDelayKind,+ MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease,+ MainDocumentStyleLoadEventBinding, StylesheetSubresourceLoadDelayBinding,};use super::load_event_gate::DocumentLoadGateRelease;use super::module_clients::{@@ -2685,6 +2685,15 @@ impl FrameOwnerStore {))}+ pub(crate) fn accept_current_main_modulepreload_event_owner(+ &self,+ owner: FrameDocumentTaskOwner,+ element: DomHandle,+ ) -> Option<MainDocumentModulepreloadEventOwner> {+ self.main_document_task_owner_is_current(owner)+ .then(|| MainDocumentModulepreloadEventOwner::new(owner, element))+ }+pub(crate) fn main_style_load_event_is_current(&self,binding: MainDocumentStyleLoadEventBinding,@@ -2900,6 +2909,21 @@ impl FrameOwnerStore {})}+ #[cfg(test)]+ pub(crate) fn current_main_document_has_style_load_event_delay(+ &self,+ owner: FrameDocumentTaskOwner,+ ) -> Option<bool> {+ if !self.main_document_task_owner_is_current(owner) {+ return None;+ }+ self.documents.get(&owner.document_id).map(|document| {+ document+ .lifecycle_progress+ .has_load_delay_reason(DocumentLoadDelayReason::StyleLoadEvent)+ })+ }+#[cfg(test)]pub(crate) fn current_main_document_has_parser_deferred_script_load_delay(&self,diff --git a/moli-renderer-v8/src/frame_owner_model/store_tests.rs b/moli-renderer-v8/src/frame_owner_model/store_tests.rsindex c1b20642c..ef03dfae4 100644--- a/moli-renderer-v8/src/frame_owner_model/store_tests.rs+++ b/moli-renderer-v8/src/frame_owner_model/store_tests.rs@@ -709,6 +709,45 @@ fn main_style_load_event_binding_delays_complete_until_event_settlement() {);}+#[test]+fn main_modulepreload_owner_never_allocates_a_load_event_delay() {+ let mut store = FrameOwnerStore::default();+ store.ensure_main_frame(+ handle(1),+ url("https://example.test/"),+ url("https://example.test/"),+ "https://example.test".to_owned(),+ policy_container(),+ policy_context(),+ None,+ );+ let snapshot = store+ .current_main_owner_snapshot()+ .expect("main owner snapshot");+ let owner = FrameDocumentTaskOwner::new(+ snapshot.scheduler_lane_id,+ snapshot.local_window_id,+ snapshot.document_id,+ );++ let event_owner = store+ .accept_current_main_modulepreload_event_owner(owner, handle(10))+ .expect("current modulepreload should retain exact event ownership");+ assert_eq!(event_owner.owner(), owner);+ assert_eq!(event_owner.element(), handle(10));+ assert_eq!(+ store.current_main_document_has_style_load_event_delay(owner),+ Some(false),+ "network-phase owner identity must not allocate a load-delay token"+ );++ assert_eq!(+ store.current_main_document_has_style_load_event_delay(owner),+ Some(false),+ "modulepreload terminal events must not touch the Document load gate"+ );+}+#[test]fn main_style_load_event_binding_cannot_settle_replacement_document() {let mut store = FrameOwnerStore::default();diff --git a/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs b/moli-renderer-v8/src/native_bridge/context_host/host_environment.rsindex da36c136d..15576510e 100644--- a/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs@@ -1033,8 +1033,21 @@ impl JsContextHost {unsafe { &*dom_host },owner,);+ let canceled_load_event_bindings =+ unsafe { &mut *self.runtime }.invalidate_style_related_state(owner);+ for binding in canceled_load_event_bindings {+ let settled = self.settle_main_style_load_event(binding);+ tracing::debug!(+ owner = ?binding.owner(),+ element = ?binding.element(),+ load_delay_token = ?binding.load_delay_token(),+ settled,+ "settled invalidated connected-style lease at CSSOM commit"+ );+ }let host_ptr = self as *mut Self;- unsafe { &mut *self.runtime }.apply_inline_cssom_source_change(host_ptr, owner);+ unsafe { &mut *self.runtime }+ .apply_inline_cssom_source_change_after_invalidation(host_ptr, owner);return true;}if self.style_engine.refresh_linked_live_stylesheet_with_host(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 18939e26c..4624e5f9d 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@@ -3,12 +3,14 @@ use crate::frame_owner_model::{DocumentLoadDelayTokenId, FrameDocumentTaskOwner, MainDocumentCompleteLifecycleAction,MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding,MainDocumentInteractiveLifecycleAction, MainDocumentLoadCompletionState,- MainDocumentMediaLoadDelayBinding, MainDocumentScriptLoadDelayKind,- MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease,- MainDocumentStyleLoadEventBinding,+ MainDocumentMediaLoadDelayBinding, MainDocumentModulepreloadEventOwner,+ MainDocumentScriptLoadDelayKind, MainDocumentScriptLoadDelayLease,+ MainDocumentScriptLoadDelayRelease, MainDocumentStyleLoadEventBinding,};use crate::{- document_runtime::DocumentRuntime,+ document_runtime::{+ ConnectedStyleLoadEventAdmission, ConnectedStyleLoadEventPlan, DocumentRuntime,+ },host::{CommittedInlineClassicScript, PreparedRuntimeScriptStartCommit, RuntimeScriptAdmission,RuntimeScriptStartPlan,@@ -163,6 +165,40 @@ impl JsContextHost {.accept_current_main_style_load_event(owner, element)}+ /// Commit the lifecycle authority for a plan prepared by+ /// `DocumentRuntime`.+ ///+ /// This method deliberately does not dereference `self.runtime`. The+ /// caller owns the mutable runtime phase, temporarily borrows the context+ /// host only for this exact FrameOwnerStore transaction, and then applies+ /// the committed value back to the runtime synchronously.+ pub(crate) fn commit_connected_style_load_event_plan(+ &mut self,+ plan: ConnectedStyleLoadEventPlan,+ ) -> Option<ConnectedStyleLoadEventAdmission> {+ match plan {+ ConnectedStyleLoadEventPlan::LoadDelaying { element } => {+ let binding = self.accept_current_main_style_load_event(element)?;+ Some(ConnectedStyleLoadEventAdmission::LoadDelaying(binding))+ }+ ConnectedStyleLoadEventPlan::NonBlockingModulepreload { element } => {+ let owner = self.accept_current_main_modulepreload_event_owner(element)?;+ Some(ConnectedStyleLoadEventAdmission::NonBlockingModulepreload(+ owner,+ ))+ }+ }+ }++ pub(crate) fn accept_current_main_modulepreload_event_owner(+ &self,+ element: crate::document_runtime::DomHandle,+ ) -> Option<MainDocumentModulepreloadEventOwner> {+ let owner = self.current_main_document_task_owner()?;+ self.frame_owner_store+ .accept_current_main_modulepreload_event_owner(owner, element)+ }+pub(crate) fn main_style_load_event_is_current(&self,binding: MainDocumentStyleLoadEventBinding,@@ -234,6 +270,15 @@ impl JsContextHost {.current_main_document_has_async_script_load_delay(owner)}+ #[cfg(test)]+ pub(crate) fn current_main_document_has_style_load_event_delay(+ &self,+ owner: FrameDocumentTaskOwner,+ ) -> Option<bool> {+ self.frame_owner_store+ .current_main_document_has_style_load_event_delay(owner)+ }+#[cfg(test)]pub(crate) fn current_main_document_has_parser_deferred_script_load_delay(&self,diff --git a/moli-renderer-v8/src/script_vm/main_document_owner.rs b/moli-renderer-v8/src/script_vm/main_document_owner.rsindex 2f214b5ec..299d29cd0 100644--- a/moli-renderer-v8/src/script_vm/main_document_owner.rs+++ b/moli-renderer-v8/src/script_vm/main_document_owner.rs@@ -4,12 +4,44 @@ use crate::frame_owner_model::{};impl ScriptVm {- #[cfg(test)]pub(crate) fn queue_initial_connected_style_loads_for_current_owner(&mut self) {- let host_ptr: *mut crate::native_bridge::JsContextHost =- self._context_host.as_ref().as_ptr();- self.document_runtime- .queue_initial_connected_style_loads_for_owner(host_ptr);+ let prepared = self+ .document_runtime+ .prepare_initial_connected_style_loads();+ self.commit_and_apply_connected_style_loads(prepared);+ }++ fn commit_and_apply_connected_style_loads(+ &mut self,+ prepared_loads: Vec<crate::document_runtime::PreparedConnectedStyleLoad>,+ ) {+ // This is a synchronous owner-thread transaction. Preparing reads the+ // DOM, committing touches only ContextHost's FrameOwnerStore, and+ // applying starts/queues the resource operation. No V8 callback, task+ // checkpoint, or event-loop turn runs between those steps.+ for prepared in prepared_loads {+ let inline_source = self+ ._context_host+ .borrow()+ .owner_style_sheet_processing_source(prepared.owner());+ let event_admission = self+ ._context_host+ .borrow_mut()+ .commit_connected_style_load_event_plan(prepared.event_plan());+ let Some(event_admission) = event_admission else {+ tracing::debug!(+ owner = ?prepared.owner(),+ "discarded connected-style plan rejected by the current main Document"+ );+ continue;+ };+ self.document_runtime.apply_prepared_connected_style_load(+ prepared,+ inline_source,+ event_admission,+ self._context_host.as_ref().as_ptr(),+ );+ }}pub(crate) fn accept_main_document_blocking_stylesheet_inputs(diff --git a/moli-renderer-v8/src/script_vm/native_module.rs b/moli-renderer-v8/src/script_vm/native_module.rsindex baeafe17d..51946eeff 100644--- a/moli-renderer-v8/src/script_vm/native_module.rs+++ b/moli-renderer-v8/src/script_vm/native_module.rs@@ -1870,13 +1870,46 @@ impl ScriptVm {request: NativeModuleSingleFetchRequest,link_client: std::sync::Arc<crate::module_runtime::NativeModulepreloadLinkClient>,) -> std::result::Result<Option<crate::module_runtime::ModulePreloadJobRun>, String> {- let start = self+ let outcome = self.document_runtime.fetch_single_native_module_for_modulepreload_link(request, link_client).map_err(|error| error.message().to_owned())?;+ let (start, pending_event) = outcome.into_parts();+ if let Some(pending_event) = pending_event {+ self.enqueue_main_modulepreload_link_event(pending_event);+ }self.run_native_modulepreload_fetch_start_for_owner(start)}+ fn enqueue_main_modulepreload_link_event(+ &mut self,+ pending_event: crate::document_runtime::PendingNativeModulepreloadLinkEvent,+ ) {+ let Some(event_owner) = pending_event.client().main_document_event_owner() else {+ tracing::debug!(+ element = ?pending_event.client().owner(),+ "discarded main modulepreload terminal without an exact Document owner"+ );+ return;+ };+ debug_assert_eq!(event_owner.element(), pending_event.client().owner());+ if !self+ ._context_host+ .borrow()+ .main_document_task_owner_is_current(event_owner.owner())+ {+ tracing::debug!(+ owner = ?event_owner.owner(),+ element = ?event_owner.element(),+ "discarded modulepreload terminal for a retired main Document"+ );+ return;+ }+ let ready = pending_event.into_ready_event();+ self.document_runtime+ .enqueue_ready_native_modulepreload_link_event(ready);+ }+fn run_native_modulepreload_fetch_start_for_owner(&mut self,start: NativeModulepreloadFetchStart,@@ -2220,12 +2253,16 @@ impl ScriptVm {.iter().all(|client| client.frame_document_client().is_none()));- self.document_runtime- .complete_native_modulepreload_link_clients(+ let pending_events = self+ .document_runtime+ .accept_native_modulepreload_link_client_terminals(&key,modulepreload_link_clients,successful,);+ for pending_event in pending_events {+ self.enqueue_main_modulepreload_link_event(pending_event);+ }self.resume_native_document_modulator_fetch_clients(&key, fetch_clients)}diff --git a/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rs b/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rsindex 2a6104914..45e6d3335 100644--- a/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rs+++ b/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rs@@ -909,13 +909,7 @@ impl ScriptVm {work: Vec<PostParsePageOwnedWork>,) -> PostParseLifecycleRound {let queue_stats = post_parse_lifecycle_queue_stats(&work);- let context_host = self._context_host.clone();- let host_ptr = context_host.as_ref().as_ptr();- let context_host = context_host.borrow();- self.document_runtime- .queue_initial_connected_style_loads_with_source_lookup(host_ptr, |owner| {- context_host.owner_style_sheet_processing_source(owner)- });+ self.queue_initial_connected_style_loads_for_current_owner();self.document_runtime.drain_document_processing_wakes();self.document_runtime.enqueue_post_parse_lifecycle_page_owned_work(page_task_queue, work, report);@@ -2022,6 +2016,16 @@ impl ScriptVm {.current_main_document_has_async_script_load_delay(owner)}+ #[cfg(test)]+ pub(crate) fn current_main_document_has_style_load_event_delay(+ &self,+ owner: crate::frame_owner_model::FrameDocumentTaskOwner,+ ) -> Option<bool> {+ self._context_host+ .borrow()+ .current_main_document_has_style_load_event_delay(owner)+ }+fn has_pending_stable_runtime_script_continuation(&mut self) -> bool {self.document_runtime.runtime_script_work_mut()diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rsindex 443b689c8..e86bd44c1 100644--- a/moli-renderer-v8/src/script_vm/tests/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs@@ -11262,6 +11262,65 @@ async fn ownerless_stylesheet_terminal_installs_for_a_late_link_client() {);}+#[test]+fn connected_stylesheet_plan_commits_its_lease_before_same_turn_apply() {+ let mut vm = new_parsed_test_vm(+ "https://style-plan-commit.test/",+ concat!(+ "<!doctype html><html><head>",+ "<style id='sheet'>body { color: black; }</style>",+ "</head><body></body></html>",+ ),+ );+ let owner = vm+ .current_main_document_task_owner()+ .expect("main Document owner");+ let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");+ vm.replace_document_resource_runtime(&loader);+ let mut prepared = vm.document_runtime.prepare_initial_connected_style_loads();+ assert_eq!(prepared.len(), 1);+ assert_eq!(+ vm.current_main_document_has_style_load_event_delay(owner),+ Some(false),+ "the pure prepare phase must not touch the Document load gate"+ );++ let prepared = prepared.pop().expect("one prepared style owner");+ let inline_source = vm+ ._context_host+ .borrow()+ .owner_style_sheet_processing_source(prepared.owner());+ let admission = vm+ ._context_host+ .borrow_mut()+ .commit_connected_style_load_event_plan(prepared.event_plan())+ .expect("the current main Document should commit the style lease");+ assert_eq!(+ vm.current_main_document_has_style_load_event_delay(owner),+ Some(true),+ "commit must acquire the lease synchronously, before runtime apply"+ );++ let host_ptr = vm._context_host.as_ref().as_ptr();+ vm.document_runtime.apply_prepared_connected_style_load(+ prepared,+ inline_source,+ admission,+ host_ptr,+ );+ let ready = vm+ .take_next_connected_style_event_body_for_test()+ .expect("same-turn apply should publish the inline style event")+ .into_ready();+ assert_eq!(+ ready+ .load_event_binding()+ .expect("stylesheet ready event must retain the committed lease")+ .owner(),+ owner+ );+}+#[test]fn main_connected_style_event_delays_complete_until_event_task_settles() {let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");@@ -13359,6 +13418,57 @@ fn new_parsed_test_vm_with_loader_and_resource_completion_queue((vm, resource_completion_queue)}+#[test]+fn connected_modulepreload_admission_never_acquires_a_network_load_delay() {+ let mut vm = new_parsed_test_vm(+ "https://example.test/page.html",+ concat!(+ "<!doctype html><html><head>",+ "<link rel='modulepreload' href='/slow-module.mjs'>",+ "</head><body></body></html>",+ ),+ );+ let owner = vm+ .current_main_document_task_owner()+ .expect("modulepreload fixture must retain a current Document owner");+ let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");+ vm.replace_document_resource_runtime(&loader);+ vm.document_runtime.insert_native_module_source(+ crate::module_runtime::ModuleMapKey::java_script(+ Url::parse("https://example.test/slow-module.mjs").expect("module URL"),+ ),+ crate::module_runtime::ModuleSource::text("export {};".to_owned()),+ );+ assert_eq!(+ vm.current_main_document_has_style_load_event_delay(owner),+ Some(false)+ );++ vm.queue_initial_connected_style_loads_for_current_owner();++ assert_eq!(+ vm.current_main_document_has_style_load_event_delay(owner),+ Some(false),+ "modulepreload network admission must retain only owner identity, not a load-delay token"+ );++ vm.prime_document_lifecycle_processing_and_record_stylesheet_network_results();+ let ready = vm+ .take_next_connected_style_event_body_for_test()+ .expect("cached modulepreload terminal should publish its link event")+ .into_ready();+ assert_eq!(+ ready.load_event_binding(),+ None,+ "a ready modulepreload terminal must not acquire a short-lived stylesheet lease"+ );+ assert_eq!(+ vm.current_main_document_has_style_load_event_delay(owner),+ Some(false),+ "modulepreload terminal publication must leave the Document load gate untouched"+ );+}+fn new_streamed_parser_test_vm(url: &str, markup: &str) -> StandaloneScriptVmHarness {let _js_runtime = crate::JsRuntime::initialize();let mut stream = HtmlParser.start_document(Url::parse(url).expect("test url"));diff --git a/moli-renderer-v8/src/stylesheet_runtime/connected.rs b/moli-renderer-v8/src/stylesheet_runtime/connected.rsindex aed67f44f..c0c32f587 100644--- a/moli-renderer-v8/src/stylesheet_runtime/connected.rs+++ b/moli-renderer-v8/src/stylesheet_runtime/connected.rs@@ -81,6 +81,93 @@ pub(crate) struct ConnectedStyleLoadPrimeResult {runtime_warnings: Vec<String>,}+/// One DOM-derived connected-style operation awaiting lifecycle commit.+///+/// The plan contains no `ContextHost` state and owns no load-delay token. Its+/// caller must commit `event_plan` and apply the result synchronously, before+/// running script or another DOM mutation.+#[derive(Debug)]+pub(crate) struct PreparedConnectedStyleLoad {+ owner: DomHandle,+ csp_blocked: bool,+ remember_before_initial_scan: bool,+ event_plan: ConnectedStyleLoadEventPlan,+}++#[derive(Debug)]+pub(crate) struct PreparedStylesheetOwnerRuntimeChange {+ owner: DomHandle,+ cached_linked_stylesheet_url: Option<Url>,+}++#[derive(Debug)]+pub(crate) struct PreparedStylesheetOwnerRuntimeChanges {+ canceled_load_event_bindings: Vec<MainDocumentStyleLoadEventBinding>,+ owner_changes: Vec<PreparedStylesheetOwnerRuntimeChange>,+}++impl PreparedStylesheetOwnerRuntimeChanges {+ fn new(+ canceled_load_event_bindings: Vec<MainDocumentStyleLoadEventBinding>,+ owner_changes: Vec<PreparedStylesheetOwnerRuntimeChange>,+ ) -> Self {+ Self {+ canceled_load_event_bindings,+ owner_changes,+ }+ }++ pub(crate) fn into_parts(+ self,+ ) -> (+ Vec<MainDocumentStyleLoadEventBinding>,+ Vec<PreparedStylesheetOwnerRuntimeChange>,+ ) {+ (self.canceled_load_event_bindings, self.owner_changes)+ }+}++impl PreparedStylesheetOwnerRuntimeChange {+ fn new(owner: DomHandle, cached_linked_stylesheet_url: Option<Url>) -> Self {+ Self {+ owner,+ cached_linked_stylesheet_url,+ }+ }++ pub(crate) fn owner(&self) -> DomHandle {+ self.owner+ }++ pub(crate) fn cached_linked_stylesheet_url(&self) -> Option<&Url> {+ self.cached_linked_stylesheet_url.as_ref()+ }+}++impl PreparedConnectedStyleLoad {+ fn new(+ owner: DomHandle,+ csp_blocked: bool,+ remember_before_initial_scan: bool,+ event_plan: ConnectedStyleLoadEventPlan,+ ) -> Self {+ Self {+ owner,+ csp_blocked,+ remember_before_initial_scan,+ event_plan,+ }+ }++ pub(crate) fn owner(&self) -> DomHandle {+ self.owner+ }++ pub(crate) fn event_plan(&self) -> ConnectedStyleLoadEventPlan {+ self.event_plan+ }+}+impl ConnectedStyleLoadPrimeResult {fn push_modulepreload_start(&mut self, start: ConnectedModulepreloadStart) {self.modulepreload_starts.push(start);@@ -249,54 +336,32 @@ async fn fetch_connected_style_import_graph(}impl DocumentRuntime {- pub(crate) fn queue_initial_connected_style_loads_with_source_lookup<F>(+ pub(crate) fn prepare_initial_connected_style_loads(&mut self,- host_ptr: *mut JsContextHost,- mut source_for: F,- ) where- F: FnMut(DomHandle) -> Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,- {+ ) -> Vec<PreparedConnectedStyleLoad> {if self.initial_connected_style_loads_queued {- return;+ return Vec::new();}self.late_preload_stylesheet_handles =self.collect_late_preload_stylesheet_handles_for_initial_scan(self.document_handle());self.initial_connected_style_loads_queued = true;- self.queue_connected_style_loads_inner(- host_ptr,- self.document_handle(),- true,- &mut source_for,- );+ let prepared = self.prepare_connected_style_loads(self.document_handle(), true);self.stylesheet_lifecycle.pre_initial_scan_processed_owners.clear();+ prepared}#[cfg(test)]pub(crate) fn queue_initial_connected_style_loads(&mut self) {- self.queue_initial_connected_style_loads_with_source_lookup(std::ptr::null_mut(), |_| None);- }-- pub(in crate::document_runtime) fn queue_connected_style_load_with_inline_source(- &mut self,- host_ptr: *mut JsContextHost,- root: DomHandle,- inline_source: Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,- ) {- let inline_source = inline_source;- self.queue_connected_style_loads_inner(host_ptr, root, false, &mut |handle| {- if handle == root {- inline_source.clone()- } else {- None- }- });+ let prepared = self.prepare_initial_connected_style_loads();+ self.commit_prepared_connected_style_loads_for_test(prepared);}#[cfg(test)]pub(crate) fn queue_connected_style_loads(&mut self, root: DomHandle) {- self.queue_connected_style_load_with_inline_source(std::ptr::null_mut(), root, None);+ let prepared = self.prepare_connected_style_loads(root, false);+ self.commit_prepared_connected_style_loads_for_test(prepared);}#[cfg(test)]@@ -353,17 +418,13 @@ impl DocumentRuntime {handles}- fn queue_connected_style_loads_inner<F>(+ pub(in crate::document_runtime) fn prepare_connected_style_loads(&mut self,- host_ptr: *mut JsContextHost,root: DomHandle,skip_existing: bool,- source_for: &mut F,- ) where- F: FnMut(DomHandle) -> Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,- {+ ) -> Vec<PreparedConnectedStyleLoad> {if !self.dom_host.is_connected(root) {- return;+ return Vec::new();}let load_handles = if self.dom_host.node(root).is_some_and(Node::is_document)|| self.dom_host.is_shadow_root(root)@@ -373,23 +434,14 @@ impl DocumentRuntime {} else {Arc::new(vec![root])};- self.queue_connected_style_load_handles_with_source_lookup(- host_ptr,- &load_handles,- skip_existing,- source_for,- );+ self.prepare_connected_style_load_handles(&load_handles, skip_existing)}- fn queue_connected_style_load_handles_with_source_lookup<F>(+ fn prepare_connected_style_load_handles(&mut self,- host_ptr: *mut JsContextHost,handles: &[DomHandle],skip_existing: bool,- source_for: &mut F,- ) where- F: FnMut(DomHandle) -> Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,- {+ ) -> Vec<PreparedConnectedStyleLoad> {let mut owners = handles.iter().copied()@@ -418,61 +470,124 @@ impl DocumentRuntime {}});}- for (handle, kind) in owners {- debug!(- handle = ?handle,- rel = self- .dom_host- .get_attribute(handle, "rel")- .unwrap_or_default(),- href = self- .dom_host- .get_attribute(handle, "href")- .unwrap_or_default(),- "processing connected style/link owner"- );- let processed_before_initial_scan = skip_existing- && self- .stylesheet_lifecycle- .pre_initial_scan_processed_owners- .contains(&handle);- if !skip_existing- || (!processed_before_initial_scan && !self.connected_style_load_is_queued(handle))- {+ owners+ .into_iter()+ .filter_map(|(handle, kind)| {+ debug!(+ handle = ?handle,+ rel = self+ .dom_host+ .get_attribute(handle, "rel")+ .unwrap_or_default(),+ href = self+ .dom_host+ .get_attribute(handle, "href")+ .unwrap_or_default(),+ "processing connected style/link owner"+ );+ let processed_before_initial_scan = skip_existing+ && self+ .stylesheet_lifecycle+ .pre_initial_scan_processed_owners+ .contains(&handle);+ if skip_existing+ && (processed_before_initial_scan+ || self.connected_style_load_is_queued(handle))+ {+ return None;+ }let csp_blocked = self.stylesheet_owner_is_csp_blocked(handle);if !csp_blocked && !kind.uses_connected_load_lifecycle() {- continue;+ return None;}- let Some(load_event_binding) =- self.accept_connected_style_load_binding(host_ptr, handle)- else {- continue;- };- if !skip_existing && !self.initial_connected_style_loads_queued {- self.stylesheet_lifecycle- .pre_initial_scan_processed_owners- .insert(handle);+ let event_plan =+ if !csp_blocked && self.connected_owner_is_non_blocking_modulepreload(handle) {+ ConnectedStyleLoadEventPlan::non_blocking_modulepreload(handle)+ } else {+ ConnectedStyleLoadEventPlan::load_delaying(handle)+ };+ Some(PreparedConnectedStyleLoad::new(+ handle,+ csp_blocked,+ !skip_existing && !self.initial_connected_style_loads_queued,+ event_plan,+ ))+ })+ .collect()+ }++ /// Apply one already-committed plan without consulting ContextHost for+ /// lifecycle authority.+ ///+ /// `host_ptr` remains only for the pre-existing synchronous live-+ /// stylesheet reads performed while priming imports. It must never be used+ /// here to acquire or upgrade a load-event lease.+ pub(crate) fn apply_prepared_connected_style_load(+ &mut self,+ prepared: PreparedConnectedStyleLoad,+ inline_source: Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,+ event_admission: ConnectedStyleLoadEventAdmission,+ host_ptr: *mut JsContextHost,+ ) {+ assert!(+ event_admission.matches_plan(prepared.event_plan),+ "connected-style commit must match its synchronously prepared plan"+ );+ let handle = prepared.owner;+ if prepared.remember_before_initial_scan {+ self.stylesheet_lifecycle+ .pre_initial_scan_processed_owners+ .insert(handle);+ }+ if prepared.csp_blocked {+ self.complete_immediate_owner_processing(+ handle,+ self.connected_style_event_element_kind(handle),+ false,+ event_admission.load_event_binding(),+ );+ return;+ }+ let inline_source = inline_source.or_else(|| self.inline_style_source_for_test(handle));+ let prime_result = self.enqueue_connected_style_load(+ handle,+ inline_source,+ host_ptr,+ Some(event_admission),+ );+ self.pending_connected_style_load_prime_result+ .extend(prime_result);+ }++ #[cfg(test)]+ fn commit_prepared_connected_style_loads_for_test(+ &mut self,+ prepared: Vec<PreparedConnectedStyleLoad>,+ ) {+ for prepared in prepared {+ let plan = prepared.event_plan();+ let admission = match plan {+ ConnectedStyleLoadEventPlan::LoadDelaying { element } => {+ ConnectedStyleLoadEventAdmission::LoadDelaying(+ MainDocumentStyleLoadEventBinding::unowned_for_document_runtime_test(+ element,+ ),+ )}- if csp_blocked {- self.complete_immediate_owner_processing(- handle,- self.connected_style_event_element_kind(handle),- false,- Some(load_event_binding),- );- continue;+ ConnectedStyleLoadEventPlan::NonBlockingModulepreload { element } => {+ ConnectedStyleLoadEventAdmission::NonBlockingModulepreload(+ crate::frame_owner_model::MainDocumentModulepreloadEventOwner::unowned_for_document_runtime_test(+ element,+ ),+ )}- let inline_source =- source_for(handle).or_else(|| self.inline_style_source_for_test(handle));- let prime_result = self.enqueue_connected_style_load(- handle,- inline_source,- host_ptr,- Some(load_event_binding),- );- self.pending_connected_style_load_prime_result- .extend(prime_result);- }+ };+ self.apply_prepared_connected_style_load(+ prepared,+ None,+ admission,+ std::ptr::null_mut(),+ );}}@@ -510,25 +625,14 @@ impl DocumentRuntime {.has_lifecycle_state(handle)}- fn accept_connected_style_load_binding(- &mut self,- host_ptr: *mut JsContextHost,- handle: DomHandle,- ) -> Option<MainDocumentStyleLoadEventBinding> {- #[cfg(test)]- if host_ptr.is_null() {- return Some(- MainDocumentStyleLoadEventBinding::unowned_for_document_runtime_test(handle),- );+ fn connected_owner_is_non_blocking_modulepreload(&self, handle: DomHandle) -> bool {+ let node_id = NodeId::new(handle.index());+ if stylesheet_link_disposition(&self.dom_host, node_id).is_some() {+ return false;}- let binding = unsafe { &mut *host_ptr }.accept_current_main_style_load_event(handle)?;- tracing::debug!(- ?handle,- owner = ?binding.owner(),- load_delay_token = ?binding.load_delay_token(),- "accepted exact main connected style load before processing"- );- Some(binding)+ connected_preload_like_link_url(&self.dom_host, node_id)+ .and_then(|url| self.connected_modulepreload_request(handle, &url))+ .is_some()}fn settle_connected_style_load_binding(@@ -557,6 +661,25 @@ impl DocumentRuntime {settled}+ fn settle_connected_style_load_admission(+ &mut self,+ host_ptr: *mut JsContextHost,+ admission: Option<ConnectedStyleLoadEventAdmission>,+ reason: &'static str,+ ) -> bool {+ self.settle_connected_style_load_binding(+ host_ptr,+ admission.and_then(ConnectedStyleLoadEventAdmission::load_event_binding),+ reason,+ )+ }++ fn load_event_binding_for_connected_admission(+ admission: Option<ConnectedStyleLoadEventAdmission>,+ ) -> Option<MainDocumentStyleLoadEventBinding> {+ admission.and_then(ConnectedStyleLoadEventAdmission::load_event_binding)+ }+#[cfg(test)]pub(crate) fn connected_style_load_is_queued_for_test(&self, handle: DomHandle) -> bool {self.connected_style_load_is_queued(handle)@@ -624,20 +747,15 @@ impl DocumentRuntime {handle: DomHandle,inline_source: Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,host_ptr: *mut JsContextHost,- load_event_binding: Option<MainDocumentStyleLoadEventBinding>,+ event_admission: Option<ConnectedStyleLoadEventAdmission>,) -> ConnectedStyleLoadPrimeResult {if self.current_document_resource_loader().is_some()&& !self.parser_created_style_import_waits_for_blocking_discovery(handle){- self.prime_connected_style_load_handle(- handle,- inline_source,- host_ptr,- load_event_binding,- )+ self.prime_connected_style_load_handle(handle, inline_source, host_ptr, event_admission)} else {self.stylesheet_lifecycle.pending_connected_loads.push_back(- QueuedConnectedStyleLoad::new(handle, inline_source, load_event_binding),+ QueuedConnectedStyleLoad::new(handle, inline_source, event_admission),);ConnectedStyleLoadPrimeResult::default()}@@ -688,7 +806,7 @@ impl DocumentRuntime {queued.owner(),queued.inline_source().cloned(),host_ptr,- queued.load_event_binding(),+ queued.event_admission(),));}result@@ -704,21 +822,48 @@ impl DocumentRuntime {handle: DomHandle,inline_source: Option<Arc<crate::style_engine::OwnerStyleSheetSource>>,host_ptr: *mut JsContextHost,- load_event_binding: Option<MainDocumentStyleLoadEventBinding>,+ event_admission: Option<ConnectedStyleLoadEventAdmission>,) -> ConnectedStyleLoadPrimeResult {let mut result = ConnectedStyleLoadPrimeResult::default();if !self.dom_host.is_connected(handle) {- self.settle_connected_style_load_binding(+ self.settle_connected_style_load_admission(host_ptr,- load_event_binding,+ event_admission,"style owner disconnected before processing",);self.invalidate_stylesheet_owner_operations(handle);return result;}+ if let Some(admission) = event_admission {+ let expects_modulepreload_identity =+ self.connected_owner_is_non_blocking_modulepreload(handle);+ let admission_matches_current_processing = matches!(+ (expects_modulepreload_identity, admission),+ (+ true,+ ConnectedStyleLoadEventAdmission::NonBlockingModulepreload(_)+ ) | (false, ConnectedStyleLoadEventAdmission::LoadDelaying(_))+ );+ if !admission_matches_current_processing {+ self.settle_connected_style_load_admission(+ host_ptr,+ Some(admission),+ "connected style owner changed after lifecycle commit",+ );+ self.invalidate_stylesheet_owner_operations(handle);+ tracing::debug!(+ ?handle,+ expects_modulepreload_identity,+ "discarded stale connected-style lifecycle commit"+ );+ return result;+ }+ }let element_kind = self.connected_style_event_element_kind(handle);let node_id = NodeId::new(handle.index());if let Some(disposition) = stylesheet_link_disposition(&self.dom_host, node_id) {+ let load_event_binding =+ Self::load_event_binding_for_connected_admission(event_admission);let stylesheet_fetcher = self.stylesheet_fetcher();let document_url = self.dom_host@@ -796,12 +941,31 @@ impl DocumentRuntime {.pending_native_modulepreload(handle).is_some_and(|client| client.key() == &key);if unchanged {+ self.settle_connected_style_load_admission(+ host_ptr,+ event_admission,+ "duplicate modulepreload owner admission",+ );return result;}- let client = NativeModulepreloadLinkClient::new_with_load_event_binding(+ let main_document_event_owner =+ event_admission.and_then(|admission| match admission {+ ConnectedStyleLoadEventAdmission::NonBlockingModulepreload(owner) => {+ Some(owner)+ }+ ConnectedStyleLoadEventAdmission::LoadDelaying(_) => None,+ });+ let Some(main_document_event_owner) = main_document_event_owner else {+ tracing::debug!(+ ?handle,+ "discarded main modulepreload without an exact Document event owner"+ );+ return result;+ };+ let client = NativeModulepreloadLinkClient::new_with_main_document_event_owner(handle,key,- load_event_binding,+ main_document_event_owner,);self.stylesheet_lifecycle.owner_states@@ -809,6 +973,8 @@ impl DocumentRuntime {result.push_modulepreload_start(ConnectedModulepreloadStart::new(preload, client));return result;}+ let load_event_binding =+ Self::load_event_binding_for_connected_admission(event_admission);if connected_modulepreload_has_non_matching_media(&self.dom_host, handle) {self.stylesheet_lifecycle.owner_states@@ -997,6 +1163,7 @@ impl DocumentRuntime {});return result;}+ let load_event_binding = Self::load_event_binding_for_connected_admission(event_admission);if let Some(source) = inline_source&& source.owner() == handle{@@ -1309,16 +1476,6 @@ impl DocumentRuntime {self.prime_pending_connected_style_loads_for_owner(host_ptr)}- #[cfg(test)]- pub(crate) fn queue_initial_connected_style_loads_for_owner(- &mut self,- host_ptr: *mut JsContextHost,- ) {- self.queue_initial_connected_style_loads_with_source_lookup(host_ptr, |owner| {- unsafe { &*host_ptr }.owner_style_sheet_processing_source(owner)- });- }-#[cfg(test)]pub(crate) fn prime_document_lifecycle_processing(&mut self) -> ConnectedStyleLoadPrimeResult {self.prime_document_lifecycle_processing_for_owner(std::ptr::null_mut())@@ -1373,7 +1530,9 @@ impl DocumentRuntime {QueuedConnectedStyleLoad::new(handle,inline_source,- operation.load_event_binding(),+ operation+ .load_event_binding()+ .map(ConnectedStyleLoadEventAdmission::LoadDelaying),),);}@@ -1474,11 +1633,10 @@ impl DocumentRuntime {}}- pub(crate) fn apply_stylesheet_owner_runtime_changes(+ pub(crate) fn prepare_stylesheet_owner_runtime_changes(&mut self,- host_ptr: *mut JsContextHost,changes: &[crate::dom::native::DomStylesheetOwnerChange],- ) {+ ) -> PreparedStylesheetOwnerRuntimeChanges {let mut transitions = Vec::<(DomHandle, bool)>::new();for change in changes {let should_queue = match change.kind() {@@ -1520,29 +1678,32 @@ impl DocumentRuntime {}}+ let mut canceled_load_event_bindings = Vec::new();+ let mut prepared = Vec::new();for (owner, should_queue) in transitions {- self.invalidate_style_related_state(host_ptr, owner);+ canceled_load_event_bindings.extend(self.invalidate_style_related_state(owner));if !should_queue {continue;}- if self.dom_host.is_html_element_named(owner, "link")- && let Some(disposition) =- stylesheet_link_disposition(&self.dom_host, NodeId::new(owner.index()))- {- let _ = unsafe { &mut *host_ptr }- .install_cached_linked_stylesheet_for_owner(owner, disposition.url());- }- let inline_source = unsafe { &*host_ptr }.owner_style_sheet_processing_source(owner);- self.queue_connected_style_load_with_inline_source(host_ptr, owner, inline_source);+ let cached_linked_stylesheet_url = self+ .dom_host+ .is_html_element_named(owner, "link")+ .then(|| stylesheet_link_disposition(&self.dom_host, NodeId::new(owner.index())))+ .flatten()+ .map(|disposition| disposition.url().clone());+ prepared.push(PreparedStylesheetOwnerRuntimeChange::new(+ owner,+ cached_linked_stylesheet_url,+ ));}+ PreparedStylesheetOwnerRuntimeChanges::new(canceled_load_event_bindings, prepared)}- pub(crate) fn apply_inline_cssom_source_change(+ pub(crate) fn apply_inline_cssom_source_change_after_invalidation(&mut self,host_ptr: *mut JsContextHost,owner: DomHandle,) {- self.invalidate_style_related_state(host_ptr, owner);self.queue_stylesheet_source_css_projection(owner);if let Some(stylesheet) = unsafe { &*host_ptr }.owner_live_stylesheet(owner) {self.prime_live_stylesheet_import_loads(owner, stylesheet, false, host_ptr);@@ -1587,9 +1748,8 @@ impl DocumentRuntime {pub(crate) fn invalidate_style_related_state(&mut self,- host_ptr: *mut JsContextHost,handle: DomHandle,- ) {+ ) -> Vec<MainDocumentStyleLoadEventBinding> {let node_id = NodeId::new(handle.index());self.stylesheet_lifecycle.pre_initial_scan_processed_owners@@ -1601,7 +1761,11 @@ impl DocumentRuntime {if candidate.owner() != handle {return true;}- canceled_bindings.extend(candidate.load_event_binding());+ canceled_bindings.extend(+ candidate+ .event_admission()+ .and_then(ConnectedStyleLoadEventAdmission::load_event_binding),+ );false});canceled_bindings.extend(@@ -1612,13 +1776,7 @@ impl DocumentRuntime {self.invalidate_stylesheet_owner_operations(handle);self.modulepreload_invalid_as_link_errors.remove(&handle);self.stylesheet_lifecycle.fetches.invalidate_node(node_id);- for binding in canceled_bindings {- self.settle_connected_style_load_binding(- host_ptr,- Some(binding),- "style processing invalidated before event posting",- );- }+ canceled_bindings}pub(crate) fn has_pending_ready_connected_style_loads(&mut self) -> bool {@@ -1789,12 +1947,13 @@ impl DocumentRuntime {self.pop_ready_connected_style_load()}- pub(crate) fn complete_native_modulepreload_link_clients(+ pub(crate) fn accept_native_modulepreload_link_client_terminals(&mut self,key: &ModuleMapKey,clients: Vec<Arc<NativeModulepreloadLinkClient>>,successful: bool,- ) {+ ) -> Vec<PendingNativeModulepreloadLinkEvent> {+ let mut accepted = Vec::new();for client in clients {if client.key() != key|| !self@@ -1804,10 +1963,20 @@ impl DocumentRuntime {{continue;}- self.push_ready_connected_style_load(- ReadyConnectedStyleLoad::for_native_modulepreload(client, successful),- );+ accepted.push(PendingNativeModulepreloadLinkEvent::new(client, successful));}+ accepted+ }++ pub(crate) fn enqueue_ready_native_modulepreload_link_event(+ &mut self,+ ready: ReadyConnectedStyleLoad,+ ) {+ debug_assert!(matches!(+ ready.operation(),+ ReadyConnectedStyleLoadOperation::NativeModulepreload(_)+ ));+ self.push_ready_connected_style_load(ready);}fn connected_modulepreload_request(@@ -1904,13 +2073,13 @@ impl DocumentRuntime {#[cfg(test)]pub(crate) fn enqueue_pending_connected_style_load_for_test(&mut self, handle: DomHandle) {let load_event_binding =- self.accept_connected_style_load_binding(std::ptr::null_mut(), handle);+ Some(MainDocumentStyleLoadEventBinding::unowned_for_document_runtime_test(handle));self.stylesheet_lifecycle.pending_connected_loads.push_back(QueuedConnectedStyleLoad::new(handle,None,- load_event_binding,+ load_event_binding.map(ConnectedStyleLoadEventAdmission::LoadDelaying),));}}@@ -2685,7 +2854,38 @@ mod tests {.all(|client| client.frame_document_client().is_none()),"main document modulator received a child modulepreload client");- runtime.complete_native_modulepreload_link_clients(&key, link_clients, successful);+ complete_modulepreload_link_clients(runtime, &key, link_clients, successful);+ }++ fn complete_modulepreload_link_clients(+ runtime: &mut DocumentRuntime,+ key: &ModuleMapKey,+ clients: Vec<Arc<NativeModulepreloadLinkClient>>,+ successful: bool,+ ) {+ let terminals =+ runtime.accept_native_modulepreload_link_client_terminals(key, clients, successful);+ for pending_event in terminals {+ runtime.enqueue_ready_native_modulepreload_link_event(pending_event.into_ready_event());+ }+ }++ #[test]+ fn pending_modulepreload_event_becomes_ready_without_a_load_event_binding() {+ let link = DomHandle::new(42);+ let key = ModuleMapKey::java_script(+ Url::parse("https://example.test/immutable-client.mjs").unwrap(),+ );+ let client = NativeModulepreloadLinkClient::new(link, key);+ let pending_event = PendingNativeModulepreloadLinkEvent::new(Arc::clone(&client), true);+ let ready = pending_event.into_ready_event();++ assert_eq!(ready.load_event_binding(), None);+ assert!(matches!(+ ready.operation(),+ ReadyConnectedStyleLoadOperation::NativeModulepreload(ready_client)+ if NativeModulepreloadLinkClient::ptr_eq(ready_client, &client)+ ));}#[test]@@ -2858,13 +3058,13 @@ mod tests {.owner_states.install_pending_native_modulepreload(Arc::clone(¤t));- runtime.complete_native_modulepreload_link_clients(&key, vec![Arc::clone(&first)], true);+ complete_modulepreload_link_clients(&mut runtime, &key, vec![Arc::clone(&first)], true);assert!(runtime.pop_ready_connected_style_load().is_none(),"an old same-key client must not acquire the current processing's event authority");- runtime.complete_native_modulepreload_link_clients(&key, vec![Arc::clone(¤t)], true);+ complete_modulepreload_link_clients(&mut runtime, &key, vec![Arc::clone(¤t)], true);let ready = runtime.pop_ready_connected_style_load().expect("current same-key client event task");@@ -2892,7 +3092,7 @@ mod tests {.stylesheet_lifecycle.owner_states.install_pending_native_modulepreload(Arc::clone(&accepted));- runtime.complete_native_modulepreload_link_clients(&key, vec![Arc::clone(&accepted)], true);+ complete_modulepreload_link_clients(&mut runtime, &key, vec![Arc::clone(&accepted)], true);runtime.stylesheet_lifecycle.owner_states@@ -2937,12 +3137,15 @@ mod tests {preload.source_url().as_str(),"https://example.test/app.mjs");+ let outcome = runtime+ .fetch_single_native_module_for_modulepreload_link(preload, link_client)+ .expect("modulepreload owner registration should succeed");+ let (fetch_start, terminal) = outcome.into_parts();assert!(matches!(- runtime- .fetch_single_native_module_for_modulepreload_link(preload, link_client)- .expect("modulepreload owner registration should succeed"),+ fetch_start,crate::module_runtime::NativeModulepreloadFetchStart::Started(_)));+ assert!(terminal.is_none());assert_eq!(runtime.script_lifecycle@@ -3277,12 +3480,21 @@ mod tests {.next().expect("connected JS modulepreload start should be present").into_parts();+ let outcome = runtime+ .fetch_single_native_module_for_modulepreload_link(preload, link_client)+ .expect("modulepreload owner registration should succeed");+ let (fetch_start, terminal) = outcome.into_parts();assert_eq!(- runtime- .fetch_single_native_module_for_modulepreload_link(preload, link_client)- .expect("modulepreload owner registration should succeed"),+ fetch_start,crate::module_runtime::NativeModulepreloadFetchStart::AlreadyComplete);+ assert!(+ runtime.pop_ready_connected_style_load().is_none(),+ "an accepted cached terminal must wait for ScriptVm lifecycle binding before enqueue"+ );+ let pending_event =+ terminal.expect("cached modulepreload should return one pending link event");+ runtime.enqueue_ready_native_modulepreload_link_event(pending_event.into_ready_event());assert!(!runtime.has_inflight_native_modulepreload_fetch(),@@ -3847,15 +4059,8 @@ mod tests {let link = first_link_handle(&document);let loader = ResourceRequestClient::new(&FetchConfig::default())?;let mut runtime = DocumentRuntime::new_networked(&document, &loader);- let load_event_binding =- MainDocumentStyleLoadEventBinding::unowned_for_document_runtime_test(link);- runtime.prime_connected_style_load_handle(- link,- None,- std::ptr::null_mut(),- Some(load_event_binding),- );+ runtime.queue_connected_style_loads(link);let first_style_client = runtime.active_stylesheet_link_client_for_test(link).expect("initial stylesheet preload client");@@ -3869,7 +4074,7 @@ mod tests {);assert!(runtime.dom_host.set_attribute(link, "rel", "modulepreload"));- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));assert!(runtime.stylesheet_lifecycle@@ -3878,14 +4083,9 @@ mod tests {.is_empty(),"stylesheet invalidation must remove its event binding");- let (modulepreload_starts, warnings) = runtime- .prime_connected_style_load_handle(- link,- None,- std::ptr::null_mut(),- Some(load_event_binding),- )- .into_parts();+ runtime.queue_connected_style_loads(link);+ let (modulepreload_starts, warnings) =+ runtime.prime_pending_connected_style_loads().into_parts();assert!(warnings.is_empty(), "runtime warnings: {warnings:?}");assert_eq!(modulepreload_starts.len(), 1);assert!(@@ -3893,18 +4093,17 @@ mod tests {.active_stylesheet_link_client_for_test(link).is_none());- assert_eq!(+ assert!(runtime.stylesheet_lifecycle.owner_states.cancelable_load_event_bindings(link)- .len(),- 1,- "only the modulepreload processing may retain an event binding"+ .is_empty(),+ "an in-flight modulepreload must retain identity without a load-delay binding");assert!(runtime.dom_host.set_attribute(link, "rel", "preload"));- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));assert!(runtime.stylesheet_lifecycle@@ -3913,12 +4112,7 @@ mod tests {.is_empty(),"modulepreload invalidation must remove its event binding");- runtime.prime_connected_style_load_handle(- link,- None,- std::ptr::null_mut(),- Some(load_event_binding),- );+ runtime.queue_connected_style_loads(link);let second_style_client = runtime.active_stylesheet_link_client_for_test(link).expect("replacement stylesheet preload client");@@ -4182,7 +4376,7 @@ mod tests {"the exact posted operation must remain the owner fact until event consumption");- runtime.invalidate_style_related_state(std::ptr::null_mut(), link);+ drop(runtime.invalidate_style_related_state(link));runtime.queue_connected_style_loads(link);let ready = prime_pending_data_stylesheet_event(&mut runtime, link).await;assert!(diff --git a/moli-renderer-v8/src/stylesheet_runtime/load.rs b/moli-renderer-v8/src/stylesheet_runtime/load.rsindex 76214a44f..78008cdcb 100644--- a/moli-renderer-v8/src/stylesheet_runtime/load.rs+++ b/moli-renderer-v8/src/stylesheet_runtime/load.rs@@ -1,7 +1,9 @@use std::sync::{Arc, OnceLock};-use crate::frame_owner_model::MainDocumentStyleLoadEventBinding;-use crate::module_runtime::NativeModulepreloadLinkClient;+use crate::frame_owner_model::{+ MainDocumentModulepreloadEventOwner, MainDocumentStyleLoadEventBinding,+};+use crate::module_runtime::{NativeModulepreloadFetchStart, NativeModulepreloadLinkClient};use crate::style_engine::OwnerStyleSheetSource;use crate::stylesheet_blocking::{StylesheetBlockingOperation, StylesheetFetch, StylesheetFetchOptions, StylesheetFetchTerminal,@@ -80,7 +82,7 @@ impl ReadyConnectedStyleLoad {}}- pub(in crate::document_runtime) fn for_native_modulepreload(+ fn for_native_modulepreload(client: Arc<NativeModulepreloadLinkClient>,successful: bool,) -> Self {@@ -108,9 +110,7 @@ impl ReadyConnectedStyleLoad {operation.load_event_binding()}ReadyConnectedStyleLoadOperation::StylesheetLink(load) => load.load_event_binding(),- ReadyConnectedStyleLoadOperation::NativeModulepreload(client) => {- client.load_event_binding()- }+ ReadyConnectedStyleLoadOperation::NativeModulepreload(_) => None,}}@@ -129,23 +129,150 @@ impl ReadyConnectedStyleLoad {}}+/// One modulepreload link event accepted by the exact connected-owner state+/// machine but not yet published to the Page task source.+///+/// Consuming this value creates the immutable ready event without touching the+/// Document load gate. The network client is never mutated during the+/// transition.+#[derive(Debug)]+pub(crate) struct PendingNativeModulepreloadLinkEvent {+ client: Arc<NativeModulepreloadLinkClient>,+ successful: bool,+}++impl PendingNativeModulepreloadLinkEvent {+ pub(in crate::document_runtime) fn new(+ client: Arc<NativeModulepreloadLinkClient>,+ successful: bool,+ ) -> Self {+ Self { client, successful }+ }++ pub(crate) fn client(&self) -> &Arc<NativeModulepreloadLinkClient> {+ &self.client+ }++ pub(crate) fn into_ready_event(self) -> ReadyConnectedStyleLoad {+ ReadyConnectedStyleLoad::for_native_modulepreload(self.client, self.successful)+ }+}++/// Result of registering one connected modulepreload link with the module+/// map. A terminal is present only when the module map was already terminal.+#[derive(Debug)]+pub(crate) struct NativeModulepreloadLinkFetchOutcome {+ fetch_start: NativeModulepreloadFetchStart,+ pending_event: Option<PendingNativeModulepreloadLinkEvent>,+}++impl NativeModulepreloadLinkFetchOutcome {+ pub(in crate::document_runtime) fn new(+ fetch_start: NativeModulepreloadFetchStart,+ pending_event: Option<PendingNativeModulepreloadLinkEvent>,+ ) -> Self {+ Self {+ fetch_start,+ pending_event,+ }+ }++ pub(crate) fn into_parts(+ self,+ ) -> (+ NativeModulepreloadFetchStart,+ Option<PendingNativeModulepreloadLinkEvent>,+ ) {+ (self.fetch_start, self.pending_event)+ }+}++/// Lifecycle work that must be committed outside `DocumentRuntime` before a+/// connected style/link owner is processed.+///+/// Preparing this value only reads the DOM. `ScriptVm` commits it while+/// safely borrowing `JsContextHost`, then gives the resulting admission back+/// to `DocumentRuntime` synchronously. No task or event-loop turn may run+/// between those phases.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) enum ConnectedStyleLoadEventPlan {+ LoadDelaying { element: DomHandle },+ NonBlockingModulepreload { element: DomHandle },+}++impl ConnectedStyleLoadEventPlan {+ pub(in crate::document_runtime) fn load_delaying(element: DomHandle) -> Self {+ Self::LoadDelaying { element }+ }++ pub(in crate::document_runtime) fn non_blocking_modulepreload(element: DomHandle) -> Self {+ Self::NonBlockingModulepreload { element }+ }+}++/// Lifecycle authority committed for one connected style/link plan.+///+/// Valid `modulepreload` links take the identity-only variant, which captures+/// the exact Document and element without touching the Document load gate.+/// All other owners retain the stylesheet load-event lease.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) enum ConnectedStyleLoadEventAdmission {+ LoadDelaying(MainDocumentStyleLoadEventBinding),+ NonBlockingModulepreload(MainDocumentModulepreloadEventOwner),+}++impl ConnectedStyleLoadEventAdmission {+ pub(in crate::document_runtime) fn matches_plan(+ self,+ plan: ConnectedStyleLoadEventPlan,+ ) -> bool {+ match (self, plan) {+ (+ Self::LoadDelaying(binding),+ ConnectedStyleLoadEventPlan::LoadDelaying { element },+ ) => binding.element() == element,+ (+ Self::NonBlockingModulepreload(owner),+ ConnectedStyleLoadEventPlan::NonBlockingModulepreload { element },+ ) => owner.element() == element,+ (+ Self::LoadDelaying(_),+ ConnectedStyleLoadEventPlan::NonBlockingModulepreload { .. },+ )+ | (+ Self::NonBlockingModulepreload(_),+ ConnectedStyleLoadEventPlan::LoadDelaying { .. },+ ) => false,+ }+ }++ pub(in crate::document_runtime) fn load_event_binding(+ self,+ ) -> Option<MainDocumentStyleLoadEventBinding> {+ match self {+ Self::LoadDelaying(binding) => Some(binding),+ Self::NonBlockingModulepreload(_) => None,+ }+ }+}+#[derive(Debug)]pub(in crate::document_runtime) struct QueuedConnectedStyleLoad {owner: DomHandle,inline_source: Option<Arc<OwnerStyleSheetSource>>,- load_event_binding: Option<MainDocumentStyleLoadEventBinding>,+ event_admission: Option<ConnectedStyleLoadEventAdmission>,}impl QueuedConnectedStyleLoad {pub(in crate::document_runtime) fn new(owner: DomHandle,inline_source: Option<Arc<OwnerStyleSheetSource>>,- load_event_binding: Option<MainDocumentStyleLoadEventBinding>,+ event_admission: Option<ConnectedStyleLoadEventAdmission>,) -> Arc<Self> {Arc::new(Self {owner,inline_source,- load_event_binding,+ event_admission,})}@@ -157,10 +284,10 @@ impl QueuedConnectedStyleLoad {self.inline_source.as_ref()}- pub(in crate::document_runtime) fn load_event_binding(+ pub(in crate::document_runtime) fn event_admission(&self,- ) -> Option<MainDocumentStyleLoadEventBinding> {- self.load_event_binding+ ) -> Option<ConnectedStyleLoadEventAdmission> {+ self.event_admission}}diff --git a/moli-renderer-v8/src/stylesheet_runtime/mod.rs b/moli-renderer-v8/src/stylesheet_runtime/mod.rsindex 7188d3080..52a0fbea1 100644--- a/moli-renderer-v8/src/stylesheet_runtime/mod.rs+++ b/moli-renderer-v8/src/stylesheet_runtime/mod.rs@@ -25,7 +25,10 @@ pub(crate) use attributes::attribute_reprocesses_connected_stylesheet;pub(crate) use blocking::OwnerlessStylesheetAdmissionError;pub(super) use client_index::StylesheetLinkClientIndex;pub(crate) use completion::{ConnectedLoadCompletion, LiveStylesheetImportLoadCompletion};-pub(crate) use connected::{ConnectedStyleLoadPrimeResult, fetch_complete_stylesheet_import_graph};+pub(crate) use connected::{+ ConnectedStyleLoadPrimeResult, PreparedConnectedStyleLoad,+ fetch_complete_stylesheet_import_graph,+};pub(super) use link_state::LinkStyleState;pub(crate) use load::StylesheetLinkClientTerminal;pub(super) use load::{@@ -34,6 +37,8 @@ pub(super) use load::{StylesheetLinkClient,};pub(crate) use load::{ConnectedStyleEventElementKind, ReadyConnectedStyleLoad};+pub(crate) use load::{ConnectedStyleLoadEventAdmission, ConnectedStyleLoadEventPlan};+pub(crate) use load::{NativeModulepreloadLinkFetchOutcome, PendingNativeModulepreloadLinkEvent};pub(super) use owner_state::{StylesheetOwnerCspDisposition, StylesheetOwnerRuntimeStates};pub(crate) use source_install::{InstallLinkedStylesheet, PreparedLinkedStylesheetResource};diff --git a/moli-renderer-v8/src/stylesheet_runtime/owner_state.rs b/moli-renderer-v8/src/stylesheet_runtime/owner_state.rsindex dcee8ee0e..8fb9a4570 100644--- a/moli-renderer-v8/src/stylesheet_runtime/owner_state.rs+++ b/moli-renderer-v8/src/stylesheet_runtime/owner_state.rs@@ -340,12 +340,6 @@ impl StylesheetOwnerRuntimeStates {{bindings.push(binding);}- if let Some(native_modulepreload) = &state.native_modulepreload- && native_modulepreload.phase == NativeModulepreloadPhase::Pending- && let Some(binding) = native_modulepreload.client.load_event_binding()- {- bindings.push(binding);- }if let Some(link) = &state.link_style_state&& let Some(binding) = link.cancelable_load_event_binding(){