Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(style): remove legacy primary cache bookkeeping
ldm05d1f2bf6af4d
diff --git a/moli-renderer-v8/src/style_engine/cache.rs b/moli-renderer-v8/src/style_engine/cache.rsindex ed4f03500..eec0b438d 100644--- a/moli-renderer-v8/src/style_engine/cache.rs+++ b/moli-renderer-v8/src/style_engine/cache.rs@@ -1,24 +1,30 @@use std::{- cell::{Cell, RefCell},+ cell::RefCell,collections::{HashMap, HashSet},};+#[cfg(test)]+use std::cell::Cell;+use style::{properties::ComputedValues, selector_parser::PseudoElement, servo_arc::Arc as ServoArc,};use crate::document_runtime::DomHandle;-/// Resolution index for canonical Stylo element data plus a pseudo-style cache.+/// Cache for computed pseudo styles that have no canonical Stylo data slot.///-/// Primary `ComputedValues` are never duplicated here: they remain owned by-/// Stylo `ElementData`. Primary entries record publication for diagnostics and-/// per-handle pseudo eviction; pseudo styles have no equivalent canonical slot-/// and are therefore retained by value until their generation is invalidated.-pub(super) struct ComputedStyleCache {+/// Primary `ComputedValues` live only in Stylo `ElementData`. Production code+/// deliberately keeps no parallel index of primary publications; invalidation+/// consults the Document's canonical element-data bucket when it needs to know+/// whether any resolved style survives. The primary ledger below exists only+/// to preserve fine-grained invalidation assertions in tests.+pub(super) struct PseudoStyleCache {+ #[cfg(test)]primary_entries: RefCell<HashSet<ComputedElementStyleCacheKey>>,pseudo_entries: RefCell<HashMap<ComputedElementStyleCacheKey, ServoArc<ComputedValues>>>,keys_by_handle: RefCell<HashMap<DomHandle, HashSet<ComputedElementStyleCacheKey>>>,+ #[cfg(test)]write_generation: Cell<u64>,}@@ -29,22 +35,26 @@ pub(super) struct ComputedElementStyleCacheKey {pub(super) pseudo_element: Option<PseudoElement>,}-impl ComputedStyleCache {+impl PseudoStyleCache {pub(super) fn new() -> Self {Self {+ #[cfg(test)]primary_entries: RefCell::new(HashSet::new()),pseudo_entries: RefCell::new(HashMap::new()),keys_by_handle: RefCell::new(HashMap::new()),+ #[cfg(test)]write_generation: Cell::new(0),}}pub(super) fn clear(&self) {+ #[cfg(test)]self.primary_entries.borrow_mut().clear();self.pseudo_entries.borrow_mut().clear();self.keys_by_handle.borrow_mut().clear();}+ #[cfg(test)]pub(super) fn record_primary(&self, key: ComputedElementStyleCacheKey) {debug_assert!(key.pseudo_element.is_none());if self.primary_entries.borrow_mut().insert(key.clone()) {@@ -73,6 +83,7 @@ impl ComputedStyleCache {.is_none();if is_new {self.index_key(&key);+ #[cfg(test)]self.bump_write_generation();}}@@ -95,10 +106,14 @@ impl ComputedStyleCache {if keys.is_empty() {return;}+ #[cfg(test)]let mut primary_entries = self.primary_entries.borrow_mut();let mut pseudo_entries = self.pseudo_entries.borrow_mut();for key in keys {- primary_entries.remove(&key);+ #[cfg(test)]+ {+ primary_entries.remove(&key);+ }pseudo_entries.remove(&key);}}@@ -111,15 +126,14 @@ impl ComputedStyleCache {.insert(key.clone());}+ #[cfg(test)]fn bump_write_generation(&self) {self.write_generation.set(self.write_generation.get().saturating_add(1));}pub(super) fn is_empty(&self) -> bool {- self.primary_entries.borrow().is_empty()- && self.pseudo_entries.borrow().is_empty()- && self.keys_by_handle.borrow().is_empty()+ self.pseudo_entries.borrow().is_empty() && self.keys_by_handle.borrow().is_empty()}#[cfg(test)]diff --git a/moli-renderer-v8/src/style_engine/cleanup.rs b/moli-renderer-v8/src/style_engine/cleanup.rsindex bdb193cf0..d5d921c39 100644--- a/moli-renderer-v8/src/style_engine/cleanup.rs+++ b/moli-renderer-v8/src/style_engine/cleanup.rs@@ -6,7 +6,7 @@ use moli_selector::StyloDomStyleAdapter;use crate::{document_runtime::DomHandle, dom::native::DomHost};use super::{- cache::ComputedStyleCache,+ cache::PseudoStyleCache,invalidation::handle_is_in_style_subtrees,outcome::{FinalizedStyleInvalidationResult, StyleInvalidationCleanupApplicationContext,@@ -15,24 +15,24 @@ use super::{state::StyleDocumentState,};-pub(super) struct StyleCacheCleanup<'a> {+pub(super) struct StyleInvalidationCleanup<'a> {document: DomHandle,dom_adapter: &'a StyloDomStyleAdapter,- computed_style_cache: &'a ComputedStyleCache,+ pseudo_style_cache: &'a PseudoStyleCache,document_state: &'a StyleDocumentState,}-impl<'a> StyleCacheCleanup<'a> {+impl<'a> StyleInvalidationCleanup<'a> {pub(super) fn new(document: DomHandle,dom_adapter: &'a StyloDomStyleAdapter,- computed_style_cache: &'a ComputedStyleCache,+ pseudo_style_cache: &'a PseudoStyleCache,document_state: &'a StyleDocumentState,) -> Self {Self {document,dom_adapter,- computed_style_cache,+ pseudo_style_cache,document_state,}}@@ -42,7 +42,7 @@ impl<'a> StyleCacheCleanup<'a> {.clear_invalidation_clear_all_fallback_reasons();self.clear_shadow_cascade_data_for_document_world();self.clear_document_element_side_tables();- self.computed_style_cache.clear();+ self.pseudo_style_cache.clear();self.document_state.clear_selector_caches();self.document_state.bump_computed_cache_generation();self.document_state.lazy_invalidation_roots.clear();@@ -180,7 +180,7 @@ impl<'a> StyleCacheCleanup<'a> {if context.clears_shadow_cascade_data_for_cleanup_target() {self.clear_shadow_cascade_data_for_document_world();}- self.computed_style_cache.clear();+ self.pseudo_style_cache.clear();self.document_state.clear_selector_caches();self.document_state.lazy_invalidation_roots.clear();self.document_state.bump_target_context_epoch();@@ -268,14 +268,14 @@ impl<'a> StyleCacheCleanup<'a> {// expansion over every published style in the document. Keep doing// the exact-root retirement even when a deferred mutation is drained// after that root was adopted into another Document: the old world- // may still own its publication marker, while the adapter moves its+ // may still own its pseudo sidecar, while the adapter moves its// ElementData to the current owner bucket on this targeted access.let immediately_invalidated = roots.iter().copied().filter(|handle| self.dom_adapter.mark_element_style_dirty(*handle)).collect::<IndexSet<_>>();- self.computed_style_cache+ self.pseudo_style_cache.invalidate_handles(roots.iter().copied());self.document_state.clear_selector_caches();self.document_state.bump_target_context_epoch();@@ -283,7 +283,7 @@ impl<'a> StyleCacheCleanup<'a> {}}-impl StyleInvalidationCleanupApplicationSink for StyleCacheCleanup<'_> {+impl StyleInvalidationCleanupApplicationSink for StyleInvalidationCleanup<'_> {fn apply_noop_cleanup_application(&self) -> bool {self.document_state.clear_invalidation_clear_all_fallback_reasons();diff --git a/moli-renderer-v8/src/style_engine/computed.rs b/moli-renderer-v8/src/style_engine/computed.rsindex c5c97d508..e5e305b8a 100644--- a/moli-renderer-v8/src/style_engine/computed.rs+++ b/moli-renderer-v8/src/style_engine/computed.rs@@ -533,7 +533,7 @@ pub(super) fn computed_style_snapshot_after_world_update(&source_stores,document_context,owner_document,- engine.cache_cleanup_for_world(&world),+ engine.invalidation_cleanup_for_world(&world),update.environment(),incremental,);@@ -758,7 +758,7 @@ fn with_resolved_style_in_current_world<R>(handle,pseudo_element: Some(pseudo_element.clone()),};- if let Some(style) = world.computed_style_cache.get_pseudo(&pseudo_key) {+ if let Some(style) = world.pseudo_style_cache.get_pseudo(&pseudo_key) {return callback(&style, None);}}@@ -785,7 +785,7 @@ fn with_resolved_style_in_current_world<R>(handle,pseudo_element: Some(pseudo_element.clone()),};- if let Some(style) = world.computed_style_cache.get_pseudo(&pseudo_key) {+ if let Some(style) = world.pseudo_style_cache.get_pseudo(&pseudo_key) {return callback(&style, None);}}@@ -841,7 +841,7 @@ fn with_resolved_style_in_current_world<R>(.get(pseudo_element).cloned()})?;- world.computed_style_cache.insert_pseudo(+ world.pseudo_style_cache.insert_pseudo(ComputedElementStyleCacheKey {computed_cache_generation,handle,@@ -851,8 +851,9 @@ fn with_resolved_style_in_current_world<R>();style} else {+ #[cfg(test)]world- .computed_style_cache+ .pseudo_style_cache.record_primary(ComputedElementStyleCacheKey {computed_cache_generation,handle,@@ -919,7 +920,7 @@ fn resolve_element_styles(validation_path,);let target = DomHandle::new(element.as_node().debug_id());- world.computed_style_cache.invalidate_handles([target]);+ world.pseudo_style_cache.invalidate_handles([target]);// `resolve_style` is the single-node initial-style API. Keep dirty// values published until this observation begins, then replace only// the demanded path from ancestors to target.@@ -1007,7 +1008,7 @@ whereif canonical_is_current && !force_descendants {continue;}- world.computed_style_cache.invalidate_handles([handle]);+ world.pseudo_style_cache.invalidate_handles([handle]);unsafe {ancestor.ensure_data().styles = ElementStyles::default();}@@ -1147,7 +1148,7 @@ fn with_lazily_resolved_pseudo_style_in_current_world<R>(handle,pseudo_element: Some(pseudo_element.clone()),};- if let Some(style) = world.computed_style_cache.get_pseudo(&computed_key) {+ if let Some(style) = world.pseudo_style_cache.get_pseudo(&computed_key) {return callback(&style);}@@ -1180,7 +1181,7 @@ fn with_lazily_resolved_pseudo_style_in_current_world<R>()})?;world- .computed_style_cache+ .pseudo_style_cache.insert_pseudo(computed_key, style.clone());callback(&style)})@@ -1203,7 +1204,7 @@ fn ensure_retained_style_system_for_computed_read(&source_stores,document_context,retained_document,- engine.cache_cleanup_for_world(world),+ engine.invalidation_cleanup_for_world(world),key,inputs,);diff --git a/moli-renderer-v8/src/style_engine/document_world.rs b/moli-renderer-v8/src/style_engine/document_world.rsindex 200c9302c..3f0af89ed 100644--- a/moli-renderer-v8/src/style_engine/document_world.rs+++ b/moli-renderer-v8/src/style_engine/document_world.rs@@ -3,7 +3,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};use crate::document_runtime::DomHandle;use super::{- cache::ComputedStyleCache,+ cache::PseudoStyleCache,pending_invalidation::PendingStyleInvalidations,pending_mutation::PendingStructuralStyleMutations,registered_properties::CssCustomPropertyRegistry,@@ -21,7 +21,7 @@ pub(super) struct DocumentStyleWorld {pub(super) document_state: StyleDocumentState,pub(super) pending_invalidations: PendingStyleInvalidations,pub(super) pending_structural_mutations: PendingStructuralStyleMutations,- pub(super) computed_style_cache: ComputedStyleCache,+ pub(super) pseudo_style_cache: PseudoStyleCache,pub(super) owner_style_sheet_sources: RefCell<OwnerStyleSheetSources>,pub(super) linked_stylesheet_sources: RefCell<LinkedStylesheetSources>,pub(super) adopted_style_sheet_sources: RefCell<AdoptedStyleSheetSources>,@@ -40,7 +40,7 @@ impl DocumentStyleWorld {document_state: StyleDocumentState::new(),pending_invalidations: PendingStyleInvalidations::new(),pending_structural_mutations: PendingStructuralStyleMutations::new(),- computed_style_cache: ComputedStyleCache::new(),+ pseudo_style_cache: PseudoStyleCache::new(),owner_style_sheet_sources: RefCell::new(OwnerStyleSheetSources::default()),linked_stylesheet_sources: RefCell::new(LinkedStylesheetSources::default()),adopted_style_sheet_sources: RefCell::new(AdoptedStyleSheetSources::default()),@@ -52,7 +52,7 @@ impl DocumentStyleWorld {self.registered_custom_properties.clear();self.pending_invalidations.clear();self.pending_structural_mutations.clear();- self.computed_style_cache.clear();+ self.pseudo_style_cache.clear();self.document_state.clear_retained_style_system();self.document_state.bump_source_set_generation();self.document_state.bump_computed_cache_generation();@@ -84,13 +84,13 @@ impl DocumentStyleWorlds {self.for_document(document).clear_for_document_replacement();}- /// Retires one handle's publication from whichever Document world last- /// exposed it. A DOM adoption can change `ownerDocument` before deferred- /// style work is drained, so consulting only the current owner would leave- /// the old world's marker behind.- pub(super) fn invalidate_computed_style_handle(&self, handle: DomHandle) {+ /// Retires one handle's cached pseudo styles from whichever Document world+ /// last exposed it. A DOM adoption can change `ownerDocument` before+ /// deferred style work is drained, so consulting only the current owner+ /// would leave the old world's pseudo values behind.+ pub(super) fn invalidate_cached_pseudos_for_handle(&self, handle: DomHandle) {for world in self.worlds.borrow().values() {- world.computed_style_cache.invalidate_handles([handle]);+ world.pseudo_style_cache.invalidate_handles([handle]);}}diff --git a/moli-renderer-v8/src/style_engine/drain.rs b/moli-renderer-v8/src/style_engine/drain.rsindex 5e8697b4d..d7aa4f9b8 100644--- a/moli-renderer-v8/src/style_engine/drain.rs+++ b/moli-renderer-v8/src/style_engine/drain.rs@@ -5,7 +5,7 @@ use crate::{document_runtime::DomHandle, dom::native::DomHost};use super::{cause::PendingStyleInvalidationWorkKind,- cleanup::StyleCacheCleanup,+ cleanup::StyleInvalidationCleanup,invalidation::StyleInvalidationCleanupEffects,outcome::{StyleInvalidationOutcome, retained_source_invalidation_outcome},pending_invalidation::{PendingStyleInvalidationBatch, PendingStyleInvalidationWork},@@ -234,7 +234,7 @@ impl PendingStyleInvalidationTargetTraceCountsSink for StyleInvalidationDrainSumpub(super) fn drain_style_invalidations(dom_adapter: &StyloDomStyleAdapter,document_state: &StyleDocumentState,- cache_cleanup: StyleCacheCleanup<'_>,+ invalidation_cleanup: StyleInvalidationCleanup<'_>,host: &DomHost,source_stores: &DocumentStyleSourceStores<'_>,document_context: StyleSourceDocumentContext<'_>,@@ -291,7 +291,7 @@ pub(super) fn drain_style_invalidations(if let Some(summary) = trace_summary {finalized_result.trace_drain_attempt(&summary);}- cache_cleanup.apply_finalized_result(host, finalized_result);+ invalidation_cleanup.apply_finalized_result(host, finalized_result);}fn diagnostic_source_lifecycle_report_for_invalidation_drain(diff --git a/moli-renderer-v8/src/style_engine/mod.rs b/moli-renderer-v8/src/style_engine/mod.rsindex 884fef457..a2a61f929 100644--- a/moli-renderer-v8/src/style_engine/mod.rs+++ b/moli-renderer-v8/src/style_engine/mod.rs@@ -95,7 +95,7 @@ mod world_lifecycle;mod world_trace;mod world_update;-use cleanup::StyleCacheCleanup;+use cleanup::StyleInvalidationCleanup;pub(crate) use computed::{ComputedDisplayKind, ComputedRenderedStyleFacts, ComputedTextTransformKind,ComputedTextWrapModeKind, ComputedWhiteSpaceCollapseKind, StyleObservationSnapshot,@@ -158,7 +158,7 @@ pub(crate) use world_update::{/// The selector/query adapter in `moli-selector` deliberately stays/// query-only. The facade owns cross-document lookup indexes plus the Stylo/// side-table adapter; style sources, retained state, invalidation state, and-/// computed cache live in per-document worlds.+/// pseudo cache live in per-document worlds.pub(crate) struct MoliStyleEngine {dom_adapter: StyloDomStyleAdapter,document_worlds: DocumentStyleWorlds,@@ -374,7 +374,7 @@ impl MoliStyleEngine {&self,document: DomHandle,) -> usize {- self.world_for_document(document).computed_style_cache.len()+ self.world_for_document(document).pseudo_style_cache.len()}#[cfg(test)]@@ -383,7 +383,7 @@ impl MoliStyleEngine {document: DomHandle,) -> u64 {self.world_for_document(document)- .computed_style_cache+ .pseudo_style_cache.write_generation()}@@ -394,7 +394,7 @@ impl MoliStyleEngine {handle: DomHandle,) -> bool {self.world_for_document(document)- .computed_style_cache+ .pseudo_style_cache.contains_handle_for_test(handle)}@@ -405,7 +405,7 @@ impl MoliStyleEngine {handle: DomHandle,) -> usize {self.world_for_document(document)- .computed_style_cache+ .pseudo_style_cache.entry_count_for_handle_for_test(handle)}@@ -639,14 +639,14 @@ impl MoliStyleEngine {.effect_count_for_test()}- pub(in crate::style_engine) fn cache_cleanup_for_world<'a>(+ pub(in crate::style_engine) fn invalidation_cleanup_for_world<'a>(&'a self,world: &'a DocumentStyleWorld,- ) -> StyleCacheCleanup<'a> {- StyleCacheCleanup::new(+ ) -> StyleInvalidationCleanup<'a> {+ StyleInvalidationCleanup::new(world.document,&self.dom_adapter,- &world.computed_style_cache,+ &world.pseudo_style_cache,&world.document_state,)}@@ -662,7 +662,7 @@ impl MoliStyleEngine {.clear_for_document_replacement(document);}- /// Drops the exact target's canonical style and publication markers after+ /// Drops the exact target's canonical style and cached pseudo values after/// it leaves every rendered style context.////// This is deliberately target-local. Subtree invalidation remains lazy;@@ -671,7 +671,7 @@ impl MoliStyleEngine {pub(crate) fn retire_computed_style_for_inactive_handle(&self, handle: DomHandle) {self.dom_adapter.clear_element_data(handle);self.document_worlds- .invalidate_computed_style_handle(handle);+ .invalidate_cached_pseudos_for_handle(handle);}fn clear_owner_document_indexes_for_document(&self, document: DomHandle) {@@ -748,7 +748,7 @@ impl MoliStyleEngine {drain_style_invalidations(&self.dom_adapter,&world.document_state,- self.cache_cleanup_for_world(&world),+ self.invalidation_cleanup_for_world(&world),host,&source_stores,document_context,diff --git a/moli-renderer-v8/src/style_engine/runtime_invalidation.rs b/moli-renderer-v8/src/style_engine/runtime_invalidation.rsindex e0d97162f..00e3f77ab 100644--- a/moli-renderer-v8/src/style_engine/runtime_invalidation.rs+++ b/moli-renderer-v8/src/style_engine/runtime_invalidation.rs@@ -130,7 +130,7 @@ impl MoliStyleEngine {effects: &[StyleMutationEffect],world: &DocumentStyleWorld,) -> bool {- if world_has_cached_style_state(world) {+ if world_has_style_state(self, world) {return false;}if mutation_effects_have_source_scope(effects) {@@ -277,7 +277,7 @@ impl MoliStyleEngine {}for (document, roots) in roots_by_document {let world = self.world_for_document(document);- self.cache_cleanup_for_world(&world)+ self.invalidation_cleanup_for_world(&world).invalidate_detached_subtrees(host, roots);}}@@ -501,7 +501,7 @@ impl MoliStyleEngine {let Some(world) = self.owner_document_world(host, root) else {return;};- self.cache_cleanup_for_world(&world)+ self.invalidation_cleanup_for_world(&world).invalidate_inline_style_subtree(host, root);}@@ -509,7 +509,7 @@ impl MoliStyleEngine {let Some(world) = self.owner_document_world(host, root) else {return;};- self.cache_cleanup_for_world(&world)+ self.invalidation_cleanup_for_world(&world).invalidate_subtrees_and_shadow_cascade_data(host, [root]);}@@ -527,7 +527,7 @@ impl MoliStyleEngine {return;};let source_stores = world.borrow_source_stores();- if !world_has_cached_style_state(world) {+ if !world_has_style_state(self, world) {world.document_state.bump_target_context_epoch();return;}@@ -580,19 +580,22 @@ impl MoliStyleEngine {for (document, roots) in roots_by_document {let world = self.world_for_document(document);cleared |= self- .cache_cleanup_for_world(&world)+ .invalidation_cleanup_for_world(&world).invalidate_subtrees(host, roots);}cleared}}-fn world_has_cached_style_state(world: &DocumentStyleWorld) -> bool {- !world.computed_style_cache.is_empty()- || world- .document_state- .try_with_retained_style_system(|_| ())- .is_some()+fn world_has_style_state(engine: &MoliStyleEngine, world: &DocumentStyleWorld) -> bool {+ world+ .document_state+ .try_with_retained_style_system(|_| ())+ .is_some()+ || engine+ .dom_adapter+ .has_element_styles_for_document(world.document)+ || !world.pseudo_style_cache.is_empty()}fn should_defer_structural_mutations(effects: &[StyleMutationEffect]) -> bool {diff --git a/moli-renderer-v8/src/style_engine/tests/outcome.rs b/moli-renderer-v8/src/style_engine/tests/outcome.rsindex 92b4af382..8ec8c6a24 100644--- a/moli-renderer-v8/src/style_engine/tests/outcome.rs+++ b/moli-renderer-v8/src/style_engine/tests/outcome.rs@@ -194,7 +194,7 @@ fn retained_target_result_preserves_fallback_reason() {}#[test]-fn source_fallback_roots_remain_compact_until_cache_cleanup() {+fn source_fallback_roots_remain_compact_until_invalidation_cleanup() {let mut host = test_host();let document = host.document_handle();let fallback_root = host.create_element("article");@@ -262,7 +262,7 @@ fn source_fallback_roots_remain_compact_until_cache_cleanup() {}#[test]-fn exact_affected_roots_remain_compact_until_cache_cleanup() {+fn exact_affected_roots_remain_compact_until_invalidation_cleanup() {let mut host = test_host();let document = host.document_handle();let exact_root = host.create_element("section");@@ -376,7 +376,7 @@ fn retained_target_result_applies_structural_boundary_cleanup_roots_on_match() {}#[test]-fn structural_boundary_roots_remain_compact_until_cache_cleanup() {+fn structural_boundary_roots_remain_compact_until_invalidation_cleanup() {let mut host = test_host();let document = host.document_handle();let structural_root = host.create_element("nav");@@ -888,7 +888,7 @@ fn mixed_cleanup_clears_shadow_cascade_data_only_for_source_fallback_roots() {let world = engine.world_for_document(document);assert!(engine- .cache_cleanup_for_world(&world)+ .invalidation_cleanup_for_world(&world).apply_finalized_result(&host, finalized_result));@@ -1731,7 +1731,7 @@ fn clear_all_fallback_application_records_reasons_in_document_world() {let world = engine.world_for_document(document);assert!(engine- .cache_cleanup_for_world(&world)+ .invalidation_cleanup_for_world(&world).apply_finalized_result(&host, outcome.finalize(&host)));@@ -1756,7 +1756,7 @@ fn clear_all_fallback_application_records_reasons_in_document_world() {assert!(!engine- .cache_cleanup_for_world(&world)+ .invalidation_cleanup_for_world(&world).apply_finalized_result(&host, StyleInvalidationOutcome::default().finalize(&host)));assert!(@@ -1872,7 +1872,7 @@ fn subtree_fallback_cleanup_clears_only_affected_shadow_cascade_data() {let world = engine.world_for_document(document);assert!(engine- .cache_cleanup_for_world(&world)+ .invalidation_cleanup_for_world(&world).apply_finalized_result(&host, finalized_result));diff --git a/moli-renderer-v8/src/style_engine/tests/subtree_cache.rs b/moli-renderer-v8/src/style_engine/tests/subtree_cache.rsindex 19c599d16..fd1041dc3 100644--- a/moli-renderer-v8/src/style_engine/tests/subtree_cache.rs+++ b/moli-renderer-v8/src/style_engine/tests/subtree_cache.rs@@ -2043,7 +2043,7 @@ fn clear_all_fallback_clears_element_styles_without_replacing_the_style_world()let world = engine.world_for_document(document);assert!(engine- .cache_cleanup_for_world(&world)+ .invalidation_cleanup_for_world(&world).apply_finalized_result(&host, outcome.finalize(&host)));assert_eq!(diff --git a/moli-renderer-v8/src/style_engine/world_lifecycle.rs b/moli-renderer-v8/src/style_engine/world_lifecycle.rsindex a0603a33e..41f13079d 100644--- a/moli-renderer-v8/src/style_engine/world_lifecycle.rs+++ b/moli-renderer-v8/src/style_engine/world_lifecycle.rs@@ -8,7 +8,7 @@ use style::context::QuirksMode;use super::{FullStyleWorldSnapshot, StyleTreeScopeVersions, StyleWorldEnvironment,- cleanup::StyleCacheCleanup,+ cleanup::StyleInvalidationCleanup,retained::{RetainedStyleInvalidations, build_retained_style_system,retained_style_system_matches_full_snapshot, update_retained_style_system,@@ -87,7 +87,7 @@ pub(super) fn ensure_retained_style_system(source_stores: &DocumentStyleSourceStores<'_>,document_context: StyleSourceDocumentContext<'_>,retained_document: DomHandle,- cache_cleanup: StyleCacheCleanup<'_>,+ invalidation_cleanup: StyleInvalidationCleanup<'_>,key: &StyleWorldKey,inputs: &FullStyleWorldSnapshot,) {@@ -140,7 +140,7 @@ pub(super) fn ensure_retained_style_system(host,dom_adapter,retained_document,- &cache_cleanup,+ &invalidation_cleanup,invalidations,);document_state.clear_source_dirty_scopes();@@ -165,7 +165,7 @@ pub(super) fn ensure_retained_style_system(// Replacing the document style world is the exceptional path. Incremental// updates above must preserve canonical ElementData so Stylo can apply the// invalidation set returned by flush().- cache_cleanup.clear_for_retained_style_system_rebuild();+ invalidation_cleanup.clear_for_retained_style_system_rebuild();document_state.clear_source_dirty_scopes();let retained = build_retained_style_system(@@ -202,7 +202,7 @@ pub(super) fn ensure_retained_style_system_incrementally(source_stores: &DocumentStyleSourceStores<'_>,document_context: StyleSourceDocumentContext<'_>,retained_document: DomHandle,- cache_cleanup: StyleCacheCleanup<'_>,+ invalidation_cleanup: StyleInvalidationCleanup<'_>,environment: &StyleWorldEnvironment,update: &IncrementalStyleWorldUpdate,) {@@ -261,7 +261,7 @@ pub(super) fn ensure_retained_style_system_incrementally(host,dom_adapter,retained_document,- &cache_cleanup,+ &invalidation_cleanup,invalidations,);document_state.clear_source_dirty_scopes();@@ -291,7 +291,7 @@ fn apply_retained_stylesheet_invalidations(host: &DomHost,dom_adapter: &StyloDomStyleAdapter,document: DomHandle,- cache_cleanup: &StyleCacheCleanup<'_>,+ invalidation_cleanup: &StyleInvalidationCleanup<'_>,invalidations: RetainedStyleInvalidations,) {let RetainedStyleInvalidations {@@ -352,18 +352,18 @@ fn apply_retained_stylesheet_invalidations());}if used_color_scheme_changed {- cache_cleanup.invalidate_subtrees(host, [document]);+ invalidation_cleanup.invalidate_subtrees(host, [document]);}- cache_cleanup.retain_stylesheet_invalidation_roots(host, stylesheet_invalidation_roots);+ invalidation_cleanup.retain_stylesheet_invalidation_roots(host, stylesheet_invalidation_roots);if document_scope_fallback {- cache_cleanup.invalidate_subtrees(host, [document]);+ invalidation_cleanup.invalidate_subtrees(host, [document]);}for shadow_root in shadow_scope_fallbacks {let mut roots = vec![shadow_root];roots.extend(host.shadow_root_host(shadow_root));- cache_cleanup.invalidate_subtrees(host, roots);+ invalidation_cleanup.invalidate_subtrees(host, roots);}- cache_cleanup.invalidate_subtrees(host, removed_shadow_scopes);+ invalidation_cleanup.invalidate_subtrees(host, removed_shadow_scopes);}fn invalidate_viewport_unit_styles(diff --git a/moli-selector/src/stylo/style_traversal.rs b/moli-selector/src/stylo/style_traversal.rsindex 27dfd8eeb..57248d99c 100644--- a/moli-selector/src/stylo/style_traversal.rs+++ b/moli-selector/src/stylo/style_traversal.rs@@ -172,10 +172,6 @@ impl StyloDomStyleAdapter {self.state.clear_element_selector_flags(handle);}- pub fn clear_element_style_values(&self, handle: NodeId) {- self.state.clear_element_style_values(handle);- }-/// Retains the element's last published computed values while marking/// them unavailable for the next style observation.pub fn mark_element_style_dirty(&self, handle: NodeId) -> bool {@@ -186,6 +182,12 @@ impl StyloDomStyleAdapter {self.state.clear_element_data_for_document(document);}+ /// Returns whether the canonical Stylo side table still contains any+ /// resolved element style for this Document.+ pub fn has_element_styles_for_document(&self, document: NodeId) -> bool {+ self.state.has_element_styles_for_document(document)+ }+pub fn set_inline_style_attribute(&self,handle: NodeId,@@ -274,15 +276,6 @@ impl StyloDomStyleAdapter {self.state.has_element_data(handle)}- pub fn element_data_count(&self) -> usize {- self.state.element_data_count()- }-- #[doc(hidden)]- pub fn element_side_table_document_count_for_test(&self) -> usize {- self.state.element_side_table_document_count_for_test()- }-#[doc(hidden)]pub fn shadow_cascade_document_count_for_test(&self) -> usize {self.state.shadow_cascade_document_count_for_test()@@ -375,59 +368,6 @@ impl<'binding> StyleDomHostBinding<'binding> {))}- // Binding-level state operations are for one synchronous style traversal:- // callers can mutate side tables while wrapper lifetimes remain scoped to- // this host binding.- pub fn clear_element_data(&self, handle: NodeId) {- self.state.clear_element_data(handle);- }-- pub fn clear_element_selector_flags(&self, handle: NodeId) {- self.state.clear_element_selector_flags(handle);- }-- pub fn clear_element_style_values(&self, handle: NodeId) {- self.state.clear_element_style_values(handle);- }-- pub fn clear_element_data_for_document(&self, document: NodeId) {- self.state.clear_element_data_for_document(document);- }-- pub fn set_inline_style_attribute(- &self,- handle: NodeId,- declarations: Arc<Locked<PropertyDeclarationBlock>>,- ) {- self.state.set_inline_style_attribute(handle, declarations);- }-- pub fn clear_inline_style_attribute(&self, handle: NodeId) {- self.state.clear_inline_style_attribute(handle);- }-- pub fn clear_inline_style_attributes_for_document(&self, document: NodeId) {- self.state- .clear_inline_style_attributes_for_document(document);- }-- pub fn element_selector_flag_handles_for_document(&self, document: NodeId) -> Vec<NodeId> {- self.state- .element_selector_flag_handles_for_document(document)- }-- pub fn clear_shadow_cascade_data_for_roots(&self, roots: impl IntoIterator<Item = NodeId>) {- self.state.clear_shadow_cascade_data_for_roots(roots);- }-- pub fn clear_shadow_cascade_data_for_document(&self, document: NodeId) {- self.state.clear_shadow_cascade_data_for_document(document);- }-- pub fn shadow_cascade_roots_for_document(&self, document: NodeId) -> Vec<NodeId> {- self.state.shadow_cascade_roots_for_document(document)- }-pub fn set_shadow_cascade_data(&self, root: NodeId, cascade_data: Arc<CascadeData>) {self.state.set_shadow_cascade_data(root, cascade_data);}@@ -445,11 +385,6 @@ impl<'binding> StyleDomHostBinding<'binding> {self.state.element_side_table_document_count_for_test()}- #[doc(hidden)]- pub fn shadow_cascade_document_count_for_test(&self) -> usize {- self.state.shadow_cascade_document_count_for_test()- }-pub(in crate::stylo) fn with_snapshot_handles<R>(&self,handles: impl IntoIterator<Item = NodeId>,@@ -585,6 +520,7 @@ impl StyloElementDataStore {});}+ #[cfg(test)]fn clear_style_values(&self, handle: NodeId) {self.remove_from_documents(handle, |bucket| {bucket.data.remove(&handle);@@ -671,6 +607,13 @@ impl StyloElementDataStore {.is_some_and(|bucket| bucket.data.contains_key(&handle))}+ fn has_style_values_for_document(&self, document: NodeId) -> bool {+ self.documents+ .borrow()+ .get(&document)+ .is_some_and(|bucket| bucket.data.values().any(|data| data.borrow().has_styles()))+ }+fn len(&self) -> usize {self.documents.borrow()@@ -1406,11 +1349,6 @@ impl StyleDomState {self.element_data.clear_selector_flags(handle);}- fn clear_element_style_values(&self, handle: NodeId) {- self.note_owner_document_if_bound(handle);- self.element_data.clear_style_values(handle);- }-fn mark_element_style_dirty(&self, handle: NodeId) -> bool {self.note_owner_document_if_bound(handle);self.element_data.mark_style_dirty(handle)@@ -1420,6 +1358,10 @@ impl StyleDomState {self.element_data.clear_data_for_document(document);}+ fn has_element_styles_for_document(&self, document: NodeId) -> bool {+ self.element_data.has_style_values_for_document(document)+ }+fn set_inline_style_attribute(&self,handle: NodeId,