fix: autosize never measured autoSize.colValueArray (#934) - #1273
Merged
Conversation
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>
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. |
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. |
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 😆 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #934, reported by @doornik in Nov 2023 with the correct diagnosis and a working fix.
The bug
getColContentSize()handed the barecolValueArraytogetColWidth()cast asany:getColWidth()measures by walkingrowInfo.startIndex..rowInfo.endIndex. On a bare array both bounds areundefined,undefined <= undefinedis 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.getRowValis 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 defaultColAutosizeMode.ContentIntelligent, the grid setscolValueArrayitself for three data types:So autosize silently failed to measure content for every boolean, date and moment column, falling back to header width.
Measured effect
Instrumenting
getColWidth, withContentIntelligent+IgnoreViewport:Array, boundsundefinedArray, boundsundefinedRowInfo8px is the width of an empty cell.
The change
The values are wrapped in a proper
RowInfo. Two details beyond the reported fix:colIndexis included —getColWidth()passes it to the formatter as the cell index, so without it formatters receiveundefined.as anybecomesas 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 viacy.intercept(nothing added toexamples/), following the existingquirk-*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, sincegetColContentSize()returnsmax(headerWidthPx, measured)and a wide header would mask a failed measurement.The precise signal: the bug collapses that
max()to exactlyheaderWidthPx, so "content beats its own header width" is what separates the two. The spec also checks its own preconditions (both columns really do take thecolValueArraypath) and keeps a plain string column as a control so the main measuring path is not broken.Verification
expected 21 to be above 21— the date column collapsed to its 21px header. Passes with the fix.tsc --noEmit,eslintand the prod build all clean, exit 0.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 ananycast hid a shape mismatch at a call boundary, and the autosize code is the least test-covered area ofslick.grid.ts— a targeted sweep for similar casts there would be worthwhile.🤖 Generated with Claude Code