{
"@medusajs/admin-sdk": "2.13.4",
"@medusajs/cli": "2.13.4",
"@medusajs/framework": "2.13.4",
"@medusajs/index": "2.13.4",
"@medusajs/medusa": "2.13.4",
"@medusajs/test-utils": "2.13.4",
"@medusajs/ui-preset": "^2.13.1"
}
v24.15.0
PostgreSQL 16.2
macOS 26.3.1
Chrome
When viewing a product's media gallery (Products → [product] → Media) and deleting the last (only) image, the page crashes with:
can't access property 'id', media[curr] is undefined
The gallery should show the empty state ("No media" with an "Edit" button).
The page crashes with a React render error. The error originates in ProductMediaGallery → Canvas component.
In product-media-gallery.tsx, handleDeleteCurrent (line 95-96) decrements curr when deleting the last item:
if (curr === media.length - 1) {
setCurr((prev) => prev - 1)
}
When there’s only one image, curr goes from 0 to -1. On re-render with an empty media array, media[-1] is undefined. The Canvas component (line 200/208) and Preview component (line 268) then crash accessing .isThumbnail, .url, and .id on undefined.
Fix Clamp curr to 0 minimum and add null guards before all media[curr] accesses:
setCurr((prev) => Math.max(0, prev - 1)) I wrote a patch for myself which resolves the issue: https://gist.github.com/appinteractive/22e812f2d430c46b35b8cff80677613c
The gallery should show the empty state ("No media" message with an "Edit" button to add new images).
The page crashes with a React render error:
can't access property 'id', media[curr] is undefined
Stack trace points to ProductMediaGallery → component in .
Canvasproduct-media-gallery.tsxThis was previously reported in #12250 and #9135 but was auto-closed as stale without a fix.