Add closest, classList, and dataset to the DOM polyfill - #619
Draft
developit wants to merge 6 commits into
Draft
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.
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
Remote code can now use three familiar DOM conveniences:
closest()starts with the element itself and walksparentElement, using the selector matcher already shared byquerySelector().classListprovides live token operations and read-only indexed access overclassName.datasetmaps camel-cased properties todata-*attribute reads, writes, and deletes.datasetlives on the sharedElementabstraction. Remote DOM deliberately keeps its element model flat, so this makes the API available to ordinary and custom elements without changingdocument.createElement(), constructor identity, or the existing prototype hierarchy. Each element lazily creates and caches one dataset proxy, preserving normal dataset object identity while keeping it live against attribute changes.classListis also cached per element.DOMTokenList.prototypeinherits from a shared proxy that supplies live numeric properties such asclassList[1]; numeric assignments are silently ignored. Internal state uses the polyfill's existing owner and value symbols. This avoids allocating a proxy per element and does not pretend the token list is an array or expose mutable array methods.These APIs do not add or widen any hooks. Class and data changes continue through the existing attribute methods, so remote synchronization sees exactly the same mutations it did before.
Tests
Added focused coverage for closest-ancestor traversal, live and indexed class updates, token operations, stable class-list and dataset identity, dataset name conversion, string coercion, deletion, and attribute hook calls.
Validated with:
pnpm exec vitest run(184 tests)pnpm type-checkpnpm lintpnpm --filter @remote-dom/polyfill buildon Node 20.20.0