Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element style iteration works only after explicitly reading from it #219

Closed
omril1 opened this issue Sep 2, 2023 · 3 comments
Closed

Element style iteration works only after explicitly reading from it #219

omril1 opened this issue Sep 2, 2023 · 3 comments

Comments

@omril1
Copy link
Contributor

omril1 commented Sep 2, 2023

It seems that iterating on an element's style iterates 0 times while it clearly shows that it has content.
After explicitly reading a property from the style or stringifying it would iterate properly on the contents of the style.

Reproduction:

const linkedom = require('linkedom');

const parser = new linkedom.DOMParser();
const e = parser.parseFromString('<html><body><div style=" display:  flex ;"></div></body></html>', 'text/html');

const divWithStyle = e.body.firstChild;

console.log(divWithStyle.hasAttribute('style')); // true
console.log(divWithStyle.getAttribute('style')); // ' display:  flex ;'
console.log(divWithStyle.style); // CSSStyleDeclaration(0) [Map] {}
console.log([...divWithStyle.style]); // []                      <------- problem
console.log(Array.from(divWithStyle.style)); // []               <------- problem
divWithStyle.style.toString();
// divWithStyle.style.display; works as well
console.log([...divWithStyle.style]); // ['display']             <------- works
console.log(Array.from(divWithStyle.style)); // ['display']      <------- works

Verified on version 0.14.25 and 0.15.2

workaround, perform a toString() on the style before iterating on it

@omril1
Copy link
Contributor Author

omril1 commented Sep 2, 2023

I believe it's because the toString() is calling updateKeys(self);

toString() {
const self = this[PRIVATE];
updateKeys(self);

Adding UpdateKeys(self) to the iterator method fixes the issue

@WebReflection
Copy link
Owner

PR welcome, thank you!

@WebReflection
Copy link
Owner

it's up and running #220

@omril1 omril1 closed this as completed Sep 16, 2023
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

No branches or pull requests

2 participants