Conversation
Implement closest, classList, and dataset by composing the existing selector, class-name, and attribute primitives. Keep remote synchronization on the unchanged hooks and cover traversal and mutation behavior.
Preserve remote-dom's flat element model instead of changing createElement and the HTML prototype hierarchy. Dataset remains a direct wrapper around data attribute operations.
Store dataset in a symbol-backed field so repeated access returns the same live object. Use a compact lazy initializer while preserving camel-case attribute normalization.
Cache a proxied DOMTokenList and route numeric properties to live tokens while rejecting indexed writes. Keep non-index properties and methods on the token-list object.
Place one proxy behind DOMTokenList.prototype so numeric lookups read live tokens and numeric assignments are ignored without allocating a proxy per element.
Store the owner and live tokens through the existing OWNER_ELEMENT and VALUE symbols. This follows the polyfill's private-state convention and avoids string-named implementation properties.
…ve selector matcher
… data attribute names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Supersedes #619, carrying @developit's six commits unchanged (authorship intact) and rebasing them onto current
main(post-#620/#625/#653). His PR description covers the core design:closest(),classList, anddatasetcomposed from the polyfill's existing selector, class-name, and attribute primitives, with no new or widened hooks.On top of that, four commits fix issues found while running this branch under a production embedder (each with the failure it prevents):
datasetkeys now enumerate — the proxy gainedhas/ownKeys/getOwnPropertyDescriptortraps, soObject.keys(el.dataset), spread,in, andfor...insee the data attributes instead of always coming back empty.Object.prototypemembers stay visible — the traps only claim actualdata-*names, so`${el.dataset}`,.toString, andhasOwnPropertywork instead of throwing on string coercion.data-fooBaris excluded fromownKeysper the HTML spec's dataset name rules, which also preventsdata-fooBar+data-foo-barfrom producing duplicate keys and a permanent proxy-invariantTypeError.matches()/closest()route through the recursive selector matcher — descendant combinators (article span) now check all ancestors instead of only the immediate parent, and the dead flat matcher is deleted.Object.defineProperty(el.dataset, …)routes through the named setter — a data descriptor writes the attribute (WebIDL[[DefineOwnProperty]]semantics) and accessor descriptors are rejected, instead of the default trap defining a non-configurable property on the proxy target and poisoning every later enumeration.Object.preventExtensions/freeze/sealthrow like a realDOMStringMap— the proxy refuses[[PreventExtensions]]as WebIDL requires of legacy platform objects, instead of letting the target become non-extensible and turning every later enumeration into a proxy-invariantTypeError.Tests
The original coverage plus 8 new tests: dataset enumeration as own properties, inherited-member visibility,
definePropertyrouting and accessor rejection,preventExtensionsrefusal, non-round-tripping name hiding, andmatches/closestdescendant-combinator traversal.Validated with:
pnpm exec vitest run(263 tests)pnpm type-checkpnpm lintpnpm --filter @remote-dom/polyfill build🤖 Generated with Claude Code