Skip to content

feat: a <template shadowrootmode> never made a shadow root - #119

Merged
jamesconwaydev merged 1 commit into
mainfrom
sync-shadow-dom
Nov 19, 2026
Merged

jamesconwaydev merged 1 commit into
mainfrom
sync-shadow-dom

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

Change

  • Syncs Netweir 0107514, feat(html): fuzzing had no assertions of the parser's own to trip netweir/netweir#344, the fuzzing assertions:

    • debug_assert!s on links after every insert and removal;
    • the stack of open elements against on_stack, and its counts;
    • the active formatting list, spans, and the chunked parser's offsets;
    • Document::check_tree() in debug builds;
    • a fix for the column-group whitespace bug the assertions found.

    Release builds are unchanged.

  • Syncs Netweir 0107514, feat(html): a <template shadowrootmode> never made a shadow root netweir/netweir#345, declarative shadow DOM:

    • Kind::ShadowRoot, attached by the HTML Standard's steps, behind Options::declarative_shadow_roots;
    • slots and the flat tree;
    • :host, :host(), :host-context() and ::slotted();
    • getHTML-style serialization.
  • parsec-capi, bindings/python, bindings/wasm: a shadow root is a DocumentFragment (node type 11), as in the DOM. EditError::NotAShadowHost maps to PARSEC_ERR_INVALID, since the C API attaches none. Options literals use ..Options::default().

  • .gitattributes: keeps crates/parsec/tests/shadow-dom/* byte for byte on Windows.

  • README: a shadow DOM bullet, and the tokenizer count corrected to 7,042. Parsec's html5lib-tests, c5495c5, is newer than Netweir's and dropped three obsolete cases.

  • ROADMAP: updated to match.

Closes #52
Closes #110

Tests

  • WPT declarative shadow DOM: 7,590 passed, 0 failed. WPT selectors: the :host parse cases now run and pass.
  • cargo test --workspace: 309 test groups, 0 failed. Tokenizer 7,042 and tree construction 3,898 passed, 0 failed. Clippy -D warnings is clean on the workspace and both bindings (wasm32 for WASM).

Syncs Netweir 0107514, bringing:

- netweir/netweir#344: debug_assert!s on the parser's invariants for
  fuzzing to trip (links after every insert and removal, the stack of
  open elements against on_stack and its counts, the active formatting
  list, spans, the chunked parser's offsets), Document::check_tree() in
  debug builds, and the column-group whitespace bug they found.
- netweir/netweir#345: declarative shadow DOM. The tree builder
  attaches shadow roots as the HTML Standard says, with slots, the flat
  tree, :host, :host(), :host-context(), ::slotted(), and getHTML-style
  serialization. WPT's declarative shadow DOM cases: 7,590 pass.

The C API and both bindings handle the new Kind::ShadowRoot (a
DocumentFragment, as the DOM has it), EditError::NotAShadowHost and
Options::declarative_shadow_roots. .gitattributes keeps the shadow DOM
test data byte for byte on Windows. The README's tokenizer count is
7,042: Parsec's html5lib-tests is newer than Netweir's and dropped
three obsolete cases.
Comment thread crates/parsec/src/dom.rs Dismissed
Comment thread crates/parsec/src/dom.rs Dismissed

@foothillsdigital foothillsdigital left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2b3d1f8.

It's a faithful sync. For tokenizer.rs, tree.rs, css.rs, dom.rs, edit.rs, serialize.rs and lib.rs, this PR's change is line for line Netweir's from 46ba93b to 0107514. shadow.rs differs only by the three-line Apache licence header every Parsec source file carries.

The Parsec-only parts (the bindings and XPath) map a shadow root to a DocumentFragment, node type 11, everywhere, as the DOM does. NotAShadowHost becomes PARSEC_ERR_INVALID in the C API, which attaches none yet. XPath leaving shadow trees out matches document.evaluate, and the module docs say so.

Checks. cargo clippy --workspace --all-targets -- -D warnings is clean, now that #117 is in. cargo test --workspace --release passes 309 tests in 37 groups. declarative shadow DOM: 7590 passed, 0 failed. The Python bindings built from this branch pass 34 tests (1 free-threaded skip).

About the failing CodeQL check. Its two high alerts, #16 and #17, are rust/cleartext-logging at dom.rs:503 and :521. Both are debug_assert! messages in insert that format node ids, plain u32 indexes ("node {child} is a document, fragment or shadow root, never a child", "node {before} isn't a child of {parent}"). CodeQL traced a value from the Python bindings' extract_pyclass_ref_trusted into the panic message and treated the panic as a log write. Nothing sensitive is in them, and debug_assert! is compiled out of release builds, so nothing can be written in what ships. I'd dismiss both as false positives; I've left that to you.

Approving.

@jamesconwaydev
jamesconwaydev merged commit f91fe06 into main Nov 19, 2026
39 checks passed
@jamesconwaydev
jamesconwaydev deleted the sync-shadow-dom branch November 19, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Declarative shadow DOM: <template shadowrootmode> attaches a shadow root Run-time assertions in the parser for fuzzing to check

3 participants