Skip to content

fix: autosize never measured autoSize.colValueArray (#934) - #1273

Merged
6pac merged 1 commit into
masterfrom
fix/934-autosize-colvaluearray
Aug 10, 2026
Merged

fix: autosize never measured autoSize.colValueArray (#934)#1273
6pac merged 1 commit into
masterfrom
fix/934-autosize-colvaluearray

Conversation

@6pac-ai

@6pac-ai 6pac-ai commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Fixes #934, reported by @doornik in Nov 2023 with the correct diagnosis and a working fix.

The bug

getColContentSize() handed the bare colValueArray to getColWidth() cast as any:

maxColWidth = this.getColWidth(columnDef, gridCanvas, autoSize.colValueArray as any);

getColWidth() measures by walking rowInfo.startIndex..rowInfo.endIndex. On a bare array both bounds are undefined, undefined <= undefined is false, so the measuring loop never ran and the column was sized to an empty cell. It didn't throw only because the loop never executed — rowInfo.getRowVal is undefined too and would have thrown on the first iteration.

It is wider than the original report

The issue was raised as affecting the reporter's own use of colValueArray. But under the default ColAutosizeMode.ContentIntelligent, the grid sets colValueArray itself for three data types:

if (colDataTypeOf === 'boolean') { autoSize.colValueArray = [true, false]; }
if (colDataTypeOf === 'date')    { autoSize.colValueArray = [new Date(...)]; }
if (colDataTypeOf === 'moment')  { autoSize.colValueArray = [moment(...)]; }

So autosize silently failed to measure content for every boolean, date and moment column, falling back to header width.

Measured effect

Instrumenting getColWidth, with ContentIntelligent + IgnoreViewport:

column rowInfo received before after
Date bare Array, bounds undefined 8px 427px
boolean bare Array, bounds undefined 8px 34px
string (control) proper RowInfo 50px 50px

8px is the width of an empty cell.

The change

The values are wrapped in a proper RowInfo. Two details beyond the reported fix:

  • colIndex is includedgetColWidth() passes it to the formatter as the cell index, so without it formatters receive undefined.
  • as any becomes as RowInfo — that cast was the root cause. It silenced exactly the shape mismatch that would otherwise have been a compile error, which is how this survived two years.

Test

cypress/e2e/quirk-autosize-colvaluearray.cy.ts, self-hosting via cy.intercept (nothing added to examples/), following the existing quirk-* specs.

It asserts on autoSize.contentSizePx — the measurement itself — rather than the final column width, because the width distribution that runs afterwards does not discriminate between the two behaviours (I checked: the date column ends up at the same final width either way). Header names are deliberately one character, since getColContentSize() returns max(headerWidthPx, measured) and a wide header would mask a failed measurement.

The precise signal: the bug collapses that max() to exactly headerWidthPx, so "content beats its own header width" is what separates the two. The spec also checks its own preconditions (both columns really do take the colValueArray path) and keeps a plain string column as a control so the main measuring path is not broken.

Verification

  • Fails on the unfixed build (fix stashed and rebuilt), both retry attempts: expected 21 to be above 21 — the date column collapsed to its 21px header. Passes with the fix.
  • tsc --noEmit, eslint and the prod build all clean, exit 0.
  • Full Cypress suite: 652 tests, 650 passing, 2 pending, 0 failing.

Note for whoever picks this up

The issue is currently labelled enhancement + PR welcome; it is a bug. Also worth a follow-up: this survived two years because an any cast hid a shape mismatch at a call boundary, and the autosize code is the least test-covered area of slick.grid.ts — a targeted sweep for similar casts there would be worthwhile.

🤖 Generated with Claude Code

getColContentSize() handed the bare colValueArray to getColWidth() cast as `any`,
but getColWidth() measures by walking rowInfo.startIndex..rowInfo.endIndex. On a
bare array both bounds are undefined, `undefined <= undefined` is false, so the
measuring loop never ran and the column was sized to an empty cell (~8px). It did
not throw only because the loop never executed - rowInfo.getRowVal is undefined
too and would have thrown on the first iteration.

This was not only the user-supplied path it was reported as. Under the default
ColAutosizeMode.ContentIntelligent the grid sets colValueArray itself for boolean,
date and moment columns, so autosize silently failed to measure content for all
three types and fell back to header width.

The values are now wrapped in a proper RowInfo. colIndex is included because
getColWidth() passes it to the formatter as the cell index, and the `any` cast is
replaced by `as RowInfo` - that cast was the root cause, silencing exactly the
shape mismatch that would otherwise have been a compile error.

Measured with the columns instrumented, ContentIntelligent + IgnoreViewport:

  column           before   after
  Date              8px     427px
  boolean           8px      34px
  string (control) 50px      50px

Adds a self-hosting regression spec asserting on autoSize.contentSizePx - the
measurement itself, isolated from the width distribution that runs afterwards,
which does not discriminate between the two behaviours. The bug collapses
max(headerWidthPx, measured) to exactly headerWidthPx, so beating one's own header
width is the precise signal that content was measured at all. Verified to fail on
the unfixed build and pass with the fix; full suite 652 tests, 650 passing,
2 pending.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@6pac

6pac commented Aug 10, 2026

Copy link
Copy Markdown
Owner

@ghiscoding this is a small fix in response to a bug report in issue 934. I'm merging it because it's simple and you don't use this code.

@6pac

6pac commented Aug 10, 2026

Copy link
Copy Markdown
Owner

BTW we are done for the moment, I suggest you do the minor release. There is still a backlog to get through, but I think that will go on forever... I need to focus on work for this week so I'll get back to it next week.

@6pac
6pac merged commit 10e2e0a into master Aug 10, 2026
3 checks passed
@6pac
6pac deleted the fix/934-autosize-colvaluearray branch August 10, 2026 01:42
@ghiscoding

Copy link
Copy Markdown
Collaborator

@6pac I can do it tomorrow after my working hours, I'll wait to see if we should merge the other RTL PR as-is or he prefers to leave it open to finish it by then. Anyway, I'll release Monday evening, that would be your Tuesday morning 😆

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.

Problem with measuring column width

3 participants