Skip to content

fix(browse): guard Delete Row against not-yet-loaded record (RUM: undefined[0] TypeError)#1545

Merged
dawsontoth merged 1 commit into
stagefrom
fix/edit-row-modal-delete-undefined-data
Jul 23, 2026
Merged

fix(browse): guard Delete Row against not-yet-loaded record (RUM: undefined[0] TypeError)#1545
dawsontoth merged 1 commit into
stagefrom
fix/edit-row-modal-delete-undefined-data

Conversation

@dawsontoth

Copy link
Copy Markdown
Contributor

Summary

Fixes an unhandled TypeError: Cannot read properties of undefined (reading '0') surfaced in Datadog RUM on the table browse view (/$organizationId/$clusterId/databases/$databaseName/$tableName/), current deploy (commit 2ccba97c).

Root cause

The Delete Row button in EditTableRowModal reads the primary-key value with data[0]?.[primaryKey]. But data is undefined while the record fetch is in flight — the parent passes data={searchByIdData?.data} (see DatabaseTableView.tsx:616-618), and the footer (containing Delete Row) renders regardless of whether data has loaded. The ?. only guarded the [primaryKey] access, not the [0] — so clicking Delete before the record resolves does undefined[0] and throws.

The prop type declared data as a non-optional array, which hid the mismatch, even though the rest of the component already treats it as optional (data?.map(...), {data ? … : <Loading/>}).

Fix

  • Make the prop type honest: data?: …[] (documents the loading state).
  • Guard the read: data?.[0]?.[primaryKey].
  • Add a regression test that renders with data={undefined} and clicks Delete Row, asserting it neither throws nor calls onDeleteRecord. (Fails the vitest run — exit 1 — without the fix.)

Datadog RUM findings

  • Error: TypeError: Cannot read properties of undefined (reading '0')handling: unhandled
  • View: /$organizationId/$clusterId/databases/$databaseName/$tableName/
  • Frequency: 2 events / 1 session / 1 user over the last 7d, all on commit 2ccba97c
  • Frame: onClick @ index-*.js (the Delete Row handler), confirmed against the deployed bundle

Verification

tsc -b, oxlint, dprint clean; full suite green (1771 passed). The race (click Delete in the window before the record fetch resolves) isn't practically reproducible in the browser preview, so the unit test — which reproduces the exact data=undefined state — is the verification.

🤖 Generated with Claude Code

The EditTableRowModal Delete Row button reads the primary-key value with
`data[0]?.[primaryKey]`, but `data` is undefined while the record fetch is in
flight — the parent passes `searchByIdData?.data` (see DatabaseTableView), and
the footer (with Delete Row) renders regardless of whether `data` has loaded.
The `?.` only guarded the `[primaryKey]` access, not `[0]`, so clicking Delete
before the record resolved threw an unhandled

  TypeError: Cannot read properties of undefined (reading '0')

on the table browse view (`/$organizationId/$clusterId/databases/$databaseName/$tableName/`),
surfaced in Datadog RUM.

Make the prop type honest (`data?: …[]`, matching the parent and the existing
`data?.map` / `{data ? … : <Loading/>}` usages) and guard the read with
`data?.[0]?.[primaryKey]`. Add a regression test that clicks Delete Row with
`data={undefined}` and asserts it neither throws nor calls onDeleteRecord.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dawsontoth
dawsontoth requested a review from a team as a code owner July 23, 2026 14:39

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request makes the data prop optional in EditTableRowModal to handle cases where the record fetch is still in flight. It adds optional chaining (data?.[0]?.[primaryKey]) to prevent an unhandled exception when clicking the "Delete Row" button before data has loaded, and includes a corresponding unit test to verify this behavior. There are no review comments to address.

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 51.88% 5559 / 10714
🔵 Statements 52.43% 5948 / 11344
🔵 Functions 44.38% 1376 / 3100
🔵 Branches 44.89% 3736 / 8322
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/features/instance/databases/modals/EditTableRowModal.tsx 60% 71.05% 50% 60% 61, 68-69, 81-138, 154-171
Generated in workflow #1572 for commit 43d4bcb by the Vitest Coverage Report Action

@cb1kenobi cb1kenobi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I ran into this once. Nice fix!

@dawsontoth
dawsontoth added this pull request to the merge queue Jul 23, 2026
Merged via the queue into stage with commit 0479bf0 Jul 23, 2026
2 checks passed
@dawsontoth
dawsontoth deleted the fix/edit-row-modal-delete-undefined-data branch July 23, 2026 18: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