Skip to content

Fix Math.max returning -Infinity when columnIndices is empty array#7728

Open
Nepomuk5665 wants to merge 2 commits intopalantir:developfrom
Nepomuk5665:fix/resize-rows-empty-array
Open

Fix Math.max returning -Infinity when columnIndices is empty array#7728
Nepomuk5665 wants to merge 2 commits intopalantir:developfrom
Nepomuk5665:fix/resize-rows-empty-array

Conversation

@Nepomuk5665
Copy link

Summary

Fixes a bug in resizeRowsByTallestCell where passing an empty array [] for the columnIndices parameter causes all rows to be resized to -Infinity height.

Problem

When resizeRowsByTallestCell is called with columnIndices = []:

  1. Line 161: columnIndicesArray becomes []
  2. Line 162: tallestByColumns becomes [] (empty after map)
  3. Line 163: Math.max(...[]) returns -Infinity

This causes all rows to have -Infinity height, which is incorrect behavior.

> Math.max(...[])
-Infinity

Solution

Add a length check before calling Math.max(). When columnIndicesArray is empty, the default value of tallest = 0 is preserved, which matches the expected behavior when no columns are specified.

Testing

This edge case was not covered by existing tests. The fix ensures consistent behavior:

  • resizeRowsByTallestCell() → uses viewport columns (existing)
  • resizeRowsByTallestCell([0, 1]) → uses specified columns (existing)
  • resizeRowsByTallestCell([]) → now correctly returns 0 height (fixed)

…sByTallestCell

When resizeRowsByTallestCell is called with an empty array for columnIndices,
Math.max(...[]) returns -Infinity, causing all rows to have -Infinity height.

This fix adds a length check to only compute the max when there are columns
to process, otherwise the default value of 0 is used, which is the expected
behavior matching the undefined columnIndices case where no columns are in view.
@palantirtech
Copy link
Member

Thanks for your interest in palantir/blueprint, @Nepomuk5665! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@changelog-app
Copy link

changelog-app bot commented Jan 24, 2026

Generate changelog in packages/table/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Fix Math.max returning -Infinity when columnIndices is empty array

Check the box to generate changelog(s)

  • Generate changelog entry

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.

2 participants