Skip to content

Conversation

@emmajam
Copy link
Contributor

@emmajam emmajam commented Jan 10, 2026

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...), the transactions variable could be undefined during certain loading states, causing the page to crash when calling .map() or accessing .length.

Screenshot 2026-01-10 at 11 10 44

Solution

Use default values in destructuring to ensure transactions is always an array:

const {
  transactions = [],
  total: approximateTotal = 0,
  hasMore = false,
} = data ?? {}

This handles both cases:

  • When data is undefined → falls back to {}, then defaults apply
  • When data.transactions is undefined → default = [] applies

Greptile Overview

Greptile Summary

Refactors the destructuring pattern for transactions, total, and hasMore to use inline default values instead of a fallback object. This ensures the variables are always initialized even when data or its properties are undefined, preventing "Cannot read properties of undefined" errors during loading states.

Confidence Score: 5/5

  • Safe to merge - clean defensive code fix that prevents runtime errors
  • The change is a straightforward refactor that improves null safety. The new pattern { 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.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/explorer/src/routes/_layout/address/$address.tsx 5/5 Refactored destructuring to use inline defaults instead of fallback object, fixing undefined access errors

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()"
Loading

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Add default values in destructuring to prevent 'Cannot read properties
of undefined (reading map/length)' errors when transactions data is
undefined during loading states.

Amp-Thread-ID: https://ampcode.com/threads/T-019ba79c-6e5b-7449-81af-3ad5fadd4e52
Co-authored-by: Amp <[email protected]>
@github-actions
Copy link

github-actions bot commented Jan 10, 2026

🚀 Deploying fix/address-page-undefined-transactions with ⚡ Cloudflare Pages

Latest commit: 277e69cc34b6068f21a1cbbbadd4932b8551b3c6
Status: ✅ Deploy successful
Preview URL: https://17c48844-explorer-moderato.porto.workers.dev
Branch Preview URL:

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@emmajam emmajam changed the title fix: handle undefined transactions on address page fix(explorer): handle undefined transactions on address page Jan 10, 2026
@jxom jxom merged commit e1525b4 into main Jan 10, 2026
9 checks passed
@jxom jxom deleted the fix/address-page-undefined-transactions branch January 10, 2026 12:44
gakonst pushed a commit that referenced this pull request Jan 15, 2026
Add default values in destructuring to prevent 'Cannot read properties
of undefined (reading map/length)' errors when transactions data is
undefined during loading states.

Amp-Thread-ID: https://ampcode.com/threads/T-019ba79c-6e5b-7449-81af-3ad5fadd4e52

Co-authored-by: Emma Jamieson-Hoare <[email protected]>
Co-authored-by: Amp <[email protected]>
gakonst pushed a commit that referenced this pull request Jan 15, 2026
Add default values in destructuring to prevent 'Cannot read properties
of undefined (reading map/length)' errors when transactions data is
undefined during loading states.

Amp-Thread-ID: https://ampcode.com/threads/T-019ba79c-6e5b-7449-81af-3ad5fadd4e52

Co-authored-by: Emma Jamieson-Hoare <[email protected]>
Co-authored-by: Amp <[email protected]>
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.

3 participants