Skip to content

fix: handle division by zero in column resize handler when startSize is 0#6215

Merged
KevinVandy merged 1 commit intoTanStack:alphafrom
solssak:fix-column-resize-from-zero
Apr 1, 2026
Merged

fix: handle division by zero in column resize handler when startSize is 0#6215
KevinVandy merged 1 commit intoTanStack:alphafrom
solssak:fix-column-resize-from-zero

Conversation

@solssak
Copy link
Copy Markdown
Contributor

@solssak solssak commented Mar 31, 2026

Summary

Fixes #6209

When a column's minSize is set to 0 and the column is resized down to 0px width, the resize handler divides by zero (deltaOffset / startSize), producing NaN. This NaN propagates into the columnSizing state, making the column permanently stuck at 0 width.

Changes

columnResizingFeature.utils.ts — two guards in updateOffset:

  1. deltaPercentage calculation: When startSize is 0, return 0 instead of deltaOffset / 0 (which produces Infinity/NaN)
  2. New column size calculation: When headerSize is 0, use absolute deltaOffset (distributed equally across leaf columns) instead of the percentage-based formula headerSize + headerSize * deltaPercentage, which always yields 0 when starting from zero

columnResizingFeature.utils.test.ts:

  • Added test: column can be resized back from zero width (verifies positive size after drag)
  • Added test: deltaPercentage is a finite number when startSize is zero (no NaN/Infinity)
  • Fixed test isolation: added missing mouseup cleanup in onChange mode test that was leaking event listeners
  • Corrected removeEventListener call count expectation (42) that was inflated by leaked listeners from prior test

Summary by CodeRabbit

  • Bug Fixes

    • Fixed column resizing calculation errors that could occur when resizing columns with minimal or zero initial sizes, preventing invalid mathematical results.
  • Tests

    • Added test coverage for column resizing edge cases with zero-sized columns to ensure robust behavior.

…is 0

When a column is resized to 0 width (with minSize: 0), the resize handler
produces NaN from deltaOffset / startSize division by zero. This NaN
propagates into columnSizing state, making the column permanently stuck.

Two fixes applied:
- Guard deltaPercentage calculation against startSize === 0
- Use absolute deltaOffset for new size when headerSize is 0, since
  percentage-based calculation (headerSize * deltaPercentage) always
  yields 0 when starting from zero

Closes TanStack#6209
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3eca6b33-2b19-4a5c-9b08-bea21f5302ad

📥 Commits

Reviewing files that changed from the base of the PR and between 2a4533e and 60f5266.

📒 Files selected for processing (2)
  • packages/table-core/src/features/column-resizing/columnResizingFeature.utils.ts
  • packages/table-core/tests/unit/features/column-resizing/columnResizingFeature.utils.test.ts

📝 Walkthrough

Walkthrough

Fixed division-by-zero errors in column resize calculations by capturing the starting size and falling back to alternative sizing logic when initial size is zero or negative. Prevents columns resized to zero width from becoming unresizable.

Changes

Cohort / File(s) Summary
Column Resize Calculation Fix
packages/table-core/src/features/column-resizing/columnResizingFeature.utils.ts
Updated delta-to-percentage calculation to check startSize <= 0 and avoid division by zero; added fallback logic to derive header sizes using deltaOffset / columnCount when individual header sizes are non-positive.
Column Resize Test Coverage
packages/table-core/tests/unit/features/column-resizing/columnResizingFeature.utils.test.ts
Added test cases for zero-sized columns with onChange mode, including mouseup event dispatch in resize workflows; asserts that resized columns achieve non-NaN sizes and deltaPercentage remains finite; adjusted event listener cleanup expectations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A column once stuck at zero width,
Now dancing free with div-by-zero fix!
No more division by nothing small,
The resizing logic handles it all. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix—handling division by zero in the column resize handler when startSize is 0—which is the core objective of this changeset.
Linked Issues check ✅ Passed The pull request fully addresses issue #6209 by implementing guard logic to prevent NaN from division by zero and providing alternative size calculation when startSize is 0, with corresponding test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the division-by-zero bug in the column resize handler and adding appropriate test coverage; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 31, 2026

View your CI Pipeline Execution ↗ for commit 60f5266

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 1m 50s View ↗
nx run-many --targets=build -p @tanstack/table-... ✅ Succeeded 21s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-31 16:44:25 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 31, 2026

More templates

@tanstack/angular-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table@6215

@tanstack/lit-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/lit-table@6215

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/TanStack/table/@tanstack/match-sorter-utils@6215

@tanstack/preact-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table@6215

@tanstack/react-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table@6215

@tanstack/react-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table-devtools@6215

@tanstack/solid-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table@6215

@tanstack/solid-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table-devtools@6215

@tanstack/svelte-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/svelte-table@6215

@tanstack/table-core

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-core@6215

@tanstack/table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-devtools@6215

@tanstack/vue-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table@6215

commit: 60f5266

@KevinVandy KevinVandy merged commit 0170047 into TanStack:alpha Apr 1, 2026
5 checks passed
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.

header.getResizeHandler() sets column size to null after it is resized to 0

2 participants