Currently it seems like elements returned from document.createElement() do not have any .dataset property, which is unexpected (https://html.spec.whatwg.org/#dom-dataset).
Please see discussion in #963; this is not possible until V8 supports proxies (and not the nonstandard Proxy.create
, but new Proxy
).
Looks like it's coming! https://twitter.com/s3ththompson/status/687301453761806336
+1 Really need this feature
Very surprised this hasn't made it in the spec, yet.
Why /lib/jsdom/browser/not-implemented.js doesn't throwing error?
For those wanting this, use _element_.setAttribute("data-foo","bar");
Any updates on this?
Boy, I just spent an hour debugging this ghost of an issue whose only symptom was that node was running out of memory. Turned out to be caused by using dataset
instead of getAttribute
. Perhaps a helper warning in the meantime would save folks from the same experience? :-/
@domenic according to this, Proxy
is supported since Node 6.
Do you have some guidelines on how you want to implement this so it'll be easier to contribute?
@idanen You will want to first implement the DOMStringMap
interface, the type of HTMLElement.prototype.dataset
. Implementing DOMStringMap
would then require changes in webidl2js
to support legacy platform objects (as defined in Web IDL) through Proxies. The Web IDL spec contains detailed instructions on what each internal method should do exactly. (Basically, stuff in the Web IDL spec goes to webidl2js, stuff in the HTML Standard goes to jsdom.)
If you were to work on this, I also recommend basing your work on my branch which will hopefully be merged soon.
@TimothyGu Something like dom-token-list ?
@idanen, no that's something entirely different.
We ran into this issue when migrating our test suite to jsdom. If it is helpful, here is the codemod I wrote to convert dataset
getters and setters to use getAttribute
and setAttribute
: https://gist.github.com/schreifels/eb6764b0435d9d830652cee7cb1132c1.
Most helpful comment
+1 Really need this feature