Skip to content

Implement live CSSGroupingRule mutation for nested media rules #330

Closed

Description

@wieslawsoltes

Parent: #239
CSS epic: #235

Proven gap

WebScene's current owner-backed stylesheet adapter supports a stable top-level cssRules list, insertRule, deleteRule, declaration mutation, media enablement, detach/reattach, and bounded staged publication. A top-level @media rule is parsed and applied, but it is exposed as a generic rule object without the CSSGroupingRule surface: cssRules, insertRule, and deleteRule are absent, nested child identity/parent links cannot be inspected, and nested mutation is impossible.

A Chromium control for @media (min-width: 1px) { .x { display:block } } proves:

  • the grouping rule is a CSSMediaRule with type 4 and normalized conditionText;
  • mediaRule.cssRules has stable CSSRuleList identity;
  • children expose parentRule === mediaRule and parentStyleSheet === sheet;
  • mediaRule.insertRule('.x { display:grid }', length) updates computed style synchronously;
  • deleting the inserted child restores style and clears that removed child's parent links;
  • out-of-range nested insert throws IndexSizeError, and missing delete index throws TypeError.

Focused scope

  • Represent nested @media children as live rule objects with stable list/rule identity and browser-shaped parent links.
  • Implement nested insertRule/deleteRule validation and synchronous observable recascade through the existing bounded owner publication path.
  • Preserve top-level behavior, owner DOM text topology, media activation, detach/reattach, navigation teardown, and the 32 MiB/256-owner staging bounds.
  • Keep @import, @namespace, constructed/adopted sheets, replace/replaceSync, other grouping-rule types, cascade/global-keyword work, and selector metadata outside this slice.

Ownership and non-overlap

Planned implementation and gates are limited to:

  • experiments/WebScene.NativeEngine.Probe/native/webscene_stylesheet_cssom_compatibility.h;
  • experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_browser_dom_tests.inc;
  • a new tests/WebPlatformSubset/contracts/cssom-grouping-rule-mutation.html;
  • a new dedicated CSSOM grouping profile/evidence file.

Do not touch #292/#245 structural DOM/listener paths, #322 generated line-height paths, #329 stream/service-worker paths, open PR #326 selector metadata, or draft #76.

Acceptance

  • Chromium/native contract matches constructor/type/condition serialization, stable rule-list identity, parent links, exceptions, synchronous computed style, and removed-child detachment.
  • Main and iframe documents preserve rule identity/order across nested insert/delete, stylesheet disable/media changes, owner detach/reattach, and navigation/teardown.
  • Nested mutation targets only the owning cascade root; unrelated nodes/rules do not receive stale or cross-document style.
  • A product-shaped nested lookup/update workload reports 20-cycle p95/max within the focused budget and bounded publication/queue counts.
  • A 100-cycle create/mutate/detach/navigation lifecycle retains <= 8 MiB V8 heap and <= 64 MiB RSS after warm-up, with no retained owners/rules/pending replacements.

Activity

  1. added
    vscode-oss/planned
    on Sep 17, 2026
  2. wieslawsoltes commented on Sep 17, 2026

    @wieslawsoltes
    CollaboratorAuthor

    Implemented and qualified on exact WebScene 8c792eedcc1bd7120455cdf589ef64fbfeec47ed in local commit 0ff4dbe4a6bcc66bd882b62510e71073e785a7d6.

    The reduced native baseline failed at the first missing semantic with TypeError: Cannot read properties of undefined (reading 'length') for CSSMediaRule.cssRules. The focused change adds live nested @media rule lists and insert/delete mutation without changing parser, cascade, runtime-task, line-height, service-worker, selector-metadata, or shared-profile paths.

    Validation:

    • Native main/iframe CSSOM identity, parent links, insert/delete, synchronous computed-style invalidation, detach/reconnect, disabled/media behavior: pass.
    • Project-owned WPT-style native contract: 1/1 document, 4/4 subtests, 524 ms.
    • Chromium 152 headless authority: CSSMediaRule / CSSRuleList, type 4, stable list identity, parent links, synchronous block→grid→block invalidation, IndexSizeError, and missing-index TypeError all match.
    • 20-cycle native profile: top-level update p95/max 10.581/10.657 ms; nested 64-rule update p95/max 2.296/3.187 ms; 4,096 nested lookups p95/max 2.519/2.524 ms.
    • 100 create/mutate/delete/detach/reconnect/remove cycles: pass. Heap 34,214,516→34,214,516 bytes; peak RSS 103,792,640→105,906,176 bytes (+2.02 MiB); native CSS rules returned to baseline; layout delta 42, scene delta 1, pending scenes <=2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vscode-oss/planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions