Skip to content

fix(grid): prevent NaN column width when hidden grid has all columns sized - 21.2.x#17462

Open
viktorkombov wants to merge 2 commits into
21.2.xfrom
vkombov/fix-17418-21.2.x
Open

fix(grid): prevent NaN column width when hidden grid has all columns sized - 21.2.x#17462
viktorkombov wants to merge 2 commits into
21.2.xfrom
vkombov/fix-17418-21.2.x

Conversation

@viktorkombov

Copy link
Copy Markdown
Contributor

Closes #17418

Description

getPossibleColumnWidth() divided the available width by columnsToSize when every visible column already had an explicit or constrained width.

When the grid is hidden through a wrapper and has no measurable width, calcWidth falls back to the sum of the column widths. In this case, computedWidth equals sumExistingWidths and columnsToSize is 0, resulting in 0 / 0 = NaN. This then poisons the cached column widths and can cause an infinite sizing loop.

When the grid is using the column-width sum fallback and there are no columns left to auto-size, return the "0px" sentinel so the existing valid column widths are preserved.

Motivation / Context

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

How Has This Been Tested?

  • Unit tests
  • Manual testing
  • Automated e2e tests

Test Configuration:

  • Angular version:
  • Browser(s):
  • OS:

Screenshots / Recordings

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

Copilot AI review requested due to automatic review settings July 24, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a grid column auto-sizing edge case where getPossibleColumnWidth() can produce NaN when the grid is hidden (no measurable width) and all visible columns already have explicit/constrained widths, which can poison cached widths and lead to a sizing loop.

Changes:

  • Added a guard in IgxGridBaseDirective.getPossibleColumnWidth() to return the "0px" sentinel in the hidden-width-sum fallback scenario.
  • Added a regression unit test that hides the grid via a display:none wrapper and verifies derived widths remain finite.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
projects/igniteui-angular/grids/grid/src/grid-base.directive.ts Adds an early-return to avoid deriving invalid column widths when grid width is computed via column-width-sum fallback.
projects/igniteui-angular/grids/grid/src/column.spec.ts Adds a regression test that reproduces the hidden-grid sizing scenario and asserts no NaN widths are derived.

Comment thread projects/igniteui-angular/grids/grid/src/column.spec.ts Outdated
Comment thread projects/igniteui-angular/grids/grid/src/grid-base.directive.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants