fix(explorer): handle undefined transactions on address page #396
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
Fix 'Cannot read properties of undefined (reading map/length)' errors on the address page.
Problem
When loading the address page (e.g.,
/address/0x...), thetransactionsvariable could beundefinedduring certain loading states, causing the page to crash when calling.map()or accessing.length.Solution
Use default values in destructuring to ensure
transactionsis always an array:This handles both cases:
dataisundefined→ falls back to{}, then defaults applydata.transactionsisundefined→ default= []appliesGreptile Overview
Greptile Summary
Refactors the destructuring pattern for
transactions,total, andhasMoreto use inline default values instead of a fallback object. This ensures the variables are always initialized even whendataor its properties are undefined, preventing "Cannot read properties of undefined" errors during loading states.Confidence Score: 5/5
{ transactions = [], ... } = data ?? {}is equivalent to the old pattern but more concise and idiomatic. Both handle the same cases: when data is undefined, it falls back to an empty object, and when data.transactions is undefined, it uses the default empty array. No functional changes or edge cases introduced.Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant Component participant Query Component->>Query: "Fetch transactions data" Query-->>Component: "Returns data or undefined" Note over Component: Before: data ?? { transactions: [], ... } Note over Component: After: { transactions = [], ... } = data ?? {} Component->>Component: "Safely access transactions.map()"(2/5) Greptile learns from your feedback when you react with thumbs up/down!