Skip to content

fix(admin): handle null sales channel references in product list and detail views#15009

Merged
kodiakhq[bot] merged 4 commits intomedusajs:developfrom
Vitalini:fix/admin-ui-orphaned-sales-channel-crash
Apr 10, 2026
Merged

fix(admin): handle null sales channel references in product list and detail views#15009
kodiakhq[bot] merged 4 commits intomedusajs:developfrom
Vitalini:fix/admin-ui-orphaned-sales-channel-crash

Conversation

@Vitalini
Copy link
Copy Markdown
Contributor

@Vitalini Vitalini commented Apr 4, 2026

What

Fixes a crash in the Admin UI when a product has orphaned sales channel references (i.e., the sales channel was deleted but the product association was not cleaned up).

Why

When a sales channel is deleted, the join table entries linking it to products are not always cleaned up. This results in the API returning null entries in the product's sales_channels array:

{
  "sales_channels": [null]
}

The Admin UI attempts to access sales_channel.name without null checks, causing:

TypeError: Cannot read properties of null (reading 'name')

This crashes both the product list page and the product detail page.

How

Added defensive null filtering in two components:

  1. SalesChannelsCell (product list table): Filters out null/undefined entries from the salesChannels array before rendering. Uses a TypeScript type guard to maintain type safety.

  2. ProductSalesChannelSection (product detail page): Filters out null/undefined entries before mapping sales channels for display.

Both components now gracefully handle orphaned references by simply excluding them from the rendered output, showing only valid sales channels.

Testing

  • Product with all valid sales channels → renders normally (no change)
  • Product with sales_channels: [null] → shows placeholder instead of crashing
  • Product with mix of valid and null channels → shows only valid channels
  • Product with sales_channels: [] or null → shows placeholder (existing behavior, unchanged)

Fixes #14945


Note

Low Risk
Low risk UI-only change that adds defensive null filtering to prevent runtime crashes when the API returns orphaned sales_channels entries; behavior change is limited to hiding invalid entries.

Overview
Prevents Admin UI crashes when products contain orphaned sales_channels entries returned as null.

Adds defensive filtering in the product list SalesChannelsCell and product detail ProductSalesChannelSection so only non-null sales channels are rendered (falling back to existing placeholder/empty states). Includes a patch changeset for @medusajs/dashboard.

Reviewed by Cursor Bugbot for commit 75478bf. Bugbot is set up for automated code reviews on this repo. Configure here.

…detail views

When a sales channel is deleted but the product-to-sales-channel
association is not cleaned up, the API returns null entries in the
product's sales_channels array. This causes the Admin UI to crash
with 'TypeError: Cannot read properties of null (reading "name")'.

This commit adds defensive null filtering in:
- SalesChannelsCell: filters out null entries before rendering the
  product list table cell
- ProductSalesChannelSection: filters out null entries before
  rendering the product detail sales channels section

Fixes medusajs#14945
@Vitalini Vitalini requested a review from a team as a code owner April 4, 2026 18:32
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 4, 2026

🦋 Changeset detected

Latest commit: 2c24627

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 77 packages
Name Type
@medusajs/dashboard Patch
@medusajs/admin-bundler Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

@Vitalini is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot bot commented Apr 9, 2026

Thank you for your contribution! 🎉

After an initial review, this PR looks good to us. Here's a summary:

✅ PR template is complete
✅ Linked to a verified issue (#14945)
✅ Changeset included (patch for @medusajs/dashboard)
✅ Follows Medusa's conventions

Notes:

  • No automated tests are included. While the fix is trivial and clear, a unit test for the null-filtering logic in both SalesChannelsCell and ProductSalesChannelSection would be preferred to guard against regressions. This is non-blocking for initial approval.
  • The fix is UI-only and addresses the symptom (crash on null entries). The underlying cause — orphaned join table rows when a sales channel is deleted — remains unaddressed on the backend. That's out of scope for this PR, but worth noting in the linked issue if it isn't already.

A team member will do a final review before this is merged. We appreciate your patience!

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 10, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin UI: Product list crashes with TypeError when product has orphaned sales channel reference

2 participants