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

Handle empty string and null for margin and padding subparts #165

Merged
merged 3 commits into from
Dec 28, 2023

Conversation

andrewiggins
Copy link
Contributor

Per the linked issue in jsdom, the following bug exists, where dom is a JSDom instance:

const elem = dom.window.document.createElement('a');

elem.style.marginTop = '10px';
console.log(elem.style.marginTop); // '10px'

elem.style.marginTop = '';
console.log(elem.style.marginTop); // Expected '', but '10px' received.

This PR fixes this bug by specifying that null and empty string are valid values for subparts of the properties margin and padding. I've also added tests for the behavior of setting these properties to undefined (value should remain as is).

Verified that this behavior (using the repro above) matches the following browser's behavior:

Chrome 119.0.6045.123
Edge 120.0.2186.2
Firefox 120.0b8
Safari 17.1 (19616.2.9.11.7)

Fixes jsdom/jsdom#2504

@andrewiggins andrewiggins changed the title Margin empty string Handle empty string and null for margin and padding subparts Nov 10, 2023
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the tests make this pretty easy to accept.

@domenic domenic merged commit 792877d into jsdom:master Dec 28, 2023
4 checks passed
@andrewiggins andrewiggins deleted the margin-empty-string branch January 4, 2024 20:54
saperdadsk added a commit to saperdadsk/react-virtualized-auto-sizer that referenced this pull request Feb 2, 2024
When reading the parent node's styles during resize, we can sometimes encounter styles with the value ''. This can happen if the node is removed from the DOM very quickly after mount (window.getComputedStyle returns '' for elements not attached to DOM). This was not handled by null-coalescing, so we need to switch to use falsy check instead.

This appears to be the same issue from bvaughn/react-virtualized#150.

Tests are not included - it looks like our JSDOM version doesn't support empty string values for css properties, as far as I can tell (See jsdom/jsdom#2504 and jsdom/cssstyle#165)
saperdadsk added a commit to saperdadsk/react-virtualized-auto-sizer that referenced this pull request Feb 2, 2024
When reading the parent node's styles during resize, we can sometimes encounter styles with the value ''. This can happen if the node is removed from the DOM very quickly after mount (window.getComputedStyle returns '' for elements not attached to DOM). This was not handled by null-coalescing, so we need to switch to use falsy check instead.

This appears to be the same issue from bvaughn/react-virtualized#150.

Tests are not included - it looks like our JSDOM version doesn't support empty string values for css properties, as far as I can tell (See jsdom/jsdom#2504 and jsdom/cssstyle#165)

Fixes bvaughn#78
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

Successfully merging this pull request may close these issues.

Style property does not changes when assign empty string
2 participants