Skip to content

chore: 🤖 add safeguards to table resize event handler#903

Merged
punkbit merged 4 commits intomainfrom
chore/add-safeguards-to-table-resize-event-handler
Mar 10, 2026
Merged

chore: 🤖 add safeguards to table resize event handler#903
punkbit merged 4 commits intomainfrom
chore/add-safeguards-to-table-resize-event-handler

Conversation

@punkbit
Copy link
Collaborator

@punkbit punkbit commented Mar 10, 2026

Why?

Fix Table column resize producing NaN width values when columnWidths array is not fully initialized.

Reported in #898 cc @rndD

How?

  • Add safeguard in Table.tsx

Preview?

demo-safe-guards-table.mov

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

🦋 Changeset detected

Latest commit: 55de404

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link

github-actions bot commented Mar 10, 2026

Claude finished @punkbit's task in 42s —— View job


Code Review

Good fix for the reported NaN issue! The change is minimal, focused, and correct. One thing to flag before merge:

💡 Suggestion (non-blocking, but worth addressing)

onKeyboardResize has the same potential issue that handleResizeStart just fixed. At Table.tsx:952-955, currentWidth and nextWidth are read from columnWidths without an undefined check:

const currentWidth = columnWidths[columnIndex];   // could be undefined
const nextWidth = columnWidths[nextColumnIndex];   // could be undefined
const newWidth = currentWidth + diff;              // → NaN if undefined
const newNextWidth = nextWidth - diff;             // → NaN if undefined

shouldUpdateColumnWidth will be false for NaN >= MIN_COLUMN_WIDTH, so the resize won't apply — but it's a silent failure. For consistency with the fix applied to handleResizeStart, consider adding the same guard here:

if (currentWidth === undefined || nextWidth === undefined) {
  return;
}

Fix this →


Everything else looks good — the undefined guard in handleResizeStart is the right approach, the changeset is properly typed as a patch, and the early return avoids any state mutation with invalid values. Nice work! 🙌

@github-actions
Copy link

github-actions bot commented Mar 10, 2026

Claude finished @punkbit's task in 27s —— View job


Code Review

  • Gather context
  • Review changed files
  • Post findings

✅ Looks great! The fix is minimal, correct, and consistently applied.

The previous review flagged that onKeyboardResize had the same potential undefined issue as handleResizeStart. This PR now addresses both:

  • handleResizeStart (Table.tsx:891-893): guards startWidth and nextStartWidth before writing to resizeStateRef
  • onKeyboardResize (Table.tsx:955-957): guards currentWidth and nextWidth before computing newWidth/newNextWidth

Both follow the same early-return pattern — clean and consistent. No other issues found. Nice work! 🙌

@workflow-authentication-public
Copy link
Contributor

📚 Storybook Preview Deployed

✅ Preview URL: https://click-6kphsnm84-clickhouse.vercel.app

Built from commit: 085962fa221817fe14e1d20d984fdef02d82da9e

@punkbit punkbit enabled auto-merge (squash) March 10, 2026 12:00
@punkbit punkbit merged commit 455f94b into main Mar 10, 2026
8 checks passed
@punkbit punkbit deleted the chore/add-safeguards-to-table-resize-event-handler branch March 10, 2026 12:01
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