fix(browse): guard Delete Row against not-yet-loaded record (RUM: undefined[0] TypeError)#1545
Merged
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
cb1kenobi
approved these changes
Jul 23, 2026
cb1kenobi
left a comment
Member
There was a problem hiding this comment.
I think I ran into this once. Nice fix!
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.
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 (commit2ccba97c).Root cause
The Delete Row button in
EditTableRowModalreads the primary-key value withdata[0]?.[primaryKey]. Butdataisundefinedwhile the record fetch is in flight — the parent passesdata={searchByIdData?.data}(seeDatabaseTableView.tsx:616-618), and the footer (containing Delete Row) renders regardless of whetherdatahas loaded. The?.only guarded the[primaryKey]access, not the[0]— so clicking Delete before the record resolves doesundefined[0]and throws.The prop type declared
dataas 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
data?: …[](documents the loading state).data?.[0]?.[primaryKey].data={undefined}and clicks Delete Row, asserting it neither throws nor callsonDeleteRecord. (Fails the vitest run — exit 1 — without the fix.)Datadog RUM findings
TypeError: Cannot read properties of undefined (reading '0')—handling: unhandled/$organizationId/$clusterId/databases/$databaseName/$tableName/2ccba97conClick @ index-*.js(the Delete Row handler), confirmed against the deployed bundleVerification
tsc -b,oxlint,dprintclean; 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 exactdata=undefinedstate — is the verification.🤖 Generated with Claude Code