fix(admin): handle null sales channel references in product list and detail views#15009
Conversation
…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
🦋 Changeset detectedLatest commit: 2c24627 The changes in this PR will be included in the next version bump. This PR includes changesets to release 77 packages
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 |
|
@Vitalini is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you for your contribution! 🎉 After an initial review, this PR looks good to us. Here's a summary: ✅ PR template is complete Notes:
A team member will do a final review before this is merged. We appreciate your patience! |
|
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. |
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
nullentries in the product'ssales_channelsarray:{ "sales_channels": [null] }The Admin UI attempts to access
sales_channel.namewithout null checks, causing:This crashes both the product list page and the product detail page.
How
Added defensive null filtering in two components:
SalesChannelsCell(product list table): Filters outnull/undefinedentries from thesalesChannelsarray before rendering. Uses a TypeScript type guard to maintain type safety.ProductSalesChannelSection(product detail page): Filters outnull/undefinedentries 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
sales_channels: [null]→ shows placeholder instead of crashingsales_channels: []ornull→ 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_channelsentries; behavior change is limited to hiding invalid entries.Overview
Prevents Admin UI crashes when products contain orphaned
sales_channelsentries returned asnull.Adds defensive filtering in the product list
SalesChannelsCelland product detailProductSalesChannelSectionso 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.