Skip to content

[Bug]: variant media filter compares variable to itself - shadowed variable #15061

@FCraven

Description

@FCraven

Package.json file

{
    "dependencies": {
      "@medusajs/medusa": "^2.13.6",
      "@medusajs/framework": "^2.13.6"
    },
    "engines": {
      "node": ">=20"
    },
    "packageManager": "[email protected]"
  }

Node.js version

v21.0.0

Database and its version

PostgreSQL 16.2

Operating system name and version

macOS 15.5 (Darwin 25.3.0)

Browser name

No response

What happended?

In the variant media section, the image filter uses a shadowed variable that compares itself to itself, making the filter always
return true.

Location: src/routes/product-variants/product-variant-detail/components/variant-media-section/variant-media-section.tsx (line 17)

// Current (broken) — inner variant shadows outer variant
const media = (variant.images || []).filter((image) =>
image.variants?.some((variant) => variant.id === variant.id) // always true
)

// Fix — rename inner variable
const media = (variant.images || []).filter((image) =>
image.variants?.some((imageVariant) => imageVariant.id === variant.id)
)

Same bug in edit-product-variant-media-form.tsx (lines 47 and 51) — affects both the assigned and unassigned image lists in the edit
modal.

Impact: All product images appear assigned to every variant. The edit modal shows all images as "already assigned" regardless of
actual assignment.

Affected versions: Confirmed in 2.13.0 through 2.13.6. Also present in compiled dist files (app.js, chunked .mjs files).

Expected behavior

Only images assigned to a specific variant should appear in that variant's media section. Unassigned images should appear in the "unassociated" list in the edit modal.

Actual behavior

All product images appear assigned to every variant because the filter compares a variable to itself (always true). The edit modal shows every image as "already assigned" regardless of actual variant association.

Link to reproduction repo

No repo needed, the bug is in the published @medusajs/dashboard package. To reproduce: 1. Create a product with multiple images 2. Create 2+ variants 3. Assign specific images to specific variants 4. Navigate to a variant's detail page . All images appear, not just the assigned ones ... or just grep the source: grep -n "variant.id === variant.id" node_modules/@medusajs/dashboard/src/routes/product-variants/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions