Distinguish DOM mutation and selector errors - #692
Conversation
|
Thanks for this. The named errors and conversion staging look right, including the narrow conversion-order fix discussed on #681. I compared 1. Preserve CSS end-of-input recovery for supported function selectorsconst root = document.createElement('section');
root.innerHTML = '<div data-kind="item"><span></span></div>';
root.querySelector('div:has(span'); // Deliberately no closing parenthesis
Please preserve this recovery and correct the test that treats 2. Avoid the duplicate ancestor walk for single-node append/prepend
I ran the existing 6,000-template fixture directly against both source snapshots, separating construction from serialization. Three rounds with alternating base/head order, Node 24.15.0, without Vitest/coverage:
The warm construction runs are roughly twice as expensive. Please avoid redundant validation on the single-node path while preserving the intended multi-argument safeguards. This demonstrates added overhead in the exact fixture that timed out in CI; it does not independently reproduce the five-second CI timeout. I would address the duplicate traversal before considering a timeout increase. 3. Cover compound-selector grammar, not just individual tokensWith the same fixture: root.querySelector('[data-kind]div');Native throws This acceptance is pre-existing, not an introduced matcher regression, but it is a gap in the new syntax-error contract. Please validate type/universal-selector placement and cover these cases through Contract and validation notes
|
|
i'm keeping this branch parked until the prerequisite stacks land, so i haven't updated this head. The structural nested- |
|
Thanks, keeping this parked until the prerequisites land and taking the structural nested- const root = document.createElement('section');
const child = document.createElement('div');
child.setAttribute('data-kind', 'item]');
root.appendChild(child);
root.querySelector('[data-kind="item]') === child;
// Native: true, despite the deliberately missing closing quote/bracket.
// Current head: SyntaxError. Base: no match.I confirmed this in isolated Chrome 153 with Please include string/attribute EOF recovery alongside the function recovery already discussed, and replace those error expectations with exact matching assertions through both query APIs plus parser coverage. Keep the genuinely malformed operator/trailing-junk cases rejected. Base's missing positive match is an inherited gap; head's new exception is separate. Deliberately unsupported CSS remains a different policy boundary. Fresh validation of this unchanged head:
The earlier compound-selector and duplicate single-node validation corrections still apply to the planned reconstruction. No need to duplicate the upstream nested- |
|
yea, added string/attribute EOF recovery to the final #692 reconstruction checklist alongside function EOF recovery, compound-selector grammar, and duplicate single-node validation. The live branch stays untouched until the prerequisites land; then i'll rebuild it on current |
23f091e to
ee48d52
Compare
|
@henrytao-me, the final reconstruction is now on current
The reconstruction also routes |
Problem
The polyfill reported invalid tree mutations with generic
Errorobjects and treated malformed or unsupported selectors as ordinary non-matches. Callers could not reliably distinguish missing children or references, hierarchy violations, invalid selector syntax, and attributes already owned by another element from unrelated failures or empty results.Impact
Minor. Consumers of the DOM-like API need stable DOM error names to make reliable decisions. Mutation failures must also be detected before nodes move or Remote DOM hooks, mutation records, and custom-element reactions publish, or the local and remote trees can diverge.
Reproduction
Malformed selectors that CSS recovers at end-of-input remain supported:
Change
DOMExceptionwhen available and a namedErrorfallback otherwise.HierarchyRequestErrorbeforeNotFoundErrorwhen both insertion conditions fail.append()andprepend()use the underlying insertion validation directly instead of walking the ancestor chain twice.:has(), and invalid compound-selector grammar withSyntaxError.:has()/:not()functions and attribute selectors, including quoted string values.Tests
Adds focused coverage for:
DOMExceptionacross public APIs;parseSelector(),querySelector(), andquerySelectorAll();:has(), and existing SVG/parser controls.Stack
This is the final polyfill remediation layer. All prerequisite PRs are merged, and this change is reconstructed as one commit directly on current
main.Validation
The reconstructed layer passes locally:
Local WPT fixtures were not downloaded. Fresh GitHub CI is green: 8/8 checks pass, including changesets, bundle size, lint, type-check, unit tests, Playwright, and classified WPT.