Skip to content

Commit

Permalink
Handle empty string values on reading parent node style
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
saperdadsk committed Feb 2, 2024
1 parent 5b929cb commit 42d43b7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/AutoSizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ export class AutoSizer extends Component<Props, State> {
// See issue #150 for more context.

const style = window.getComputedStyle(this._parentNode) || {};
const paddingLeft = parseFloat(style.paddingLeft ?? "0");
const paddingRight = parseFloat(style.paddingRight ?? "0");
const paddingTop = parseFloat(style.paddingTop ?? "0");
const paddingBottom = parseFloat(style.paddingBottom ?? "0");
const paddingLeft = parseFloat(style.paddingLeft || "0");
const paddingRight = parseFloat(style.paddingRight || "0");
const paddingTop = parseFloat(style.paddingTop || "0");
const paddingBottom = parseFloat(style.paddingBottom || "0");

const rect = this._parentNode.getBoundingClientRect();
const scaledHeight = rect.height - paddingTop - paddingBottom;
Expand Down

0 comments on commit 42d43b7

Please sign in to comment.