Fix product list crash with orphaned sales channel references#14961
Fix product list crash with orphaned sales channel references#14961moktamd wants to merge 1 commit intomedusajs:developfrom
Conversation
🦋 Changeset detectedLatest commit: 5d71df8 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 |
|
@moktamd 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 reviewing this PR, we need a few things addressed before we can move forward: Required changes:
Notes:
.filter((sc): sc is SalesChannelDTO => sc !== null && sc !== undefined)This ensures downstream
|
Filter out null entries from sales_channels arrays before rendering. When a sales channel is deleted without cleaning up the join table, the API returns null entries that crash the Admin UI with TypeError.
cd07c4a to
5d71df8
Compare
|
Thanks for the review — addressed everything:
Agreed on the backend root cause — happy to open a follow-up issue for cleaning up orphaned join-table rows on sales channel deletion if that'd be useful. |
Fixes #14945
Summary
What — Filters out null/orphaned sales channel entries in the product list table and product detail views.
Why — When a sales channel is deleted without cleaning up the product-to-sales-channel join table, the API returns
nullentries inproduct.sales_channels. The dashboard crashes withTypeError: Cannot read properties of null (reading 'name')when rendering these entries.How — Replaced unguarded
.map()calls with a type-safe filter predicate that narrows(SalesChannelDTO | null)[]toSalesChannelDTO[]before accessing.nameor.id. Applied in bothSalesChannelsCell(product list table) andProductSalesChannelSection(product detail page).Testing — To reproduce:
Checklist
yarn changeset—@medusajs/dashboardpatch)Note
Low Risk
Low-risk UI robustness change that filters out
nullsales channel entries to prevent runtime crashes when orphaned associations are returned by the API.Overview
Prevents product list/detail rendering crashes when
product.sales_channelscontains orphanednullentries by filtering them out with type-guard predicates before mapping/printing channelname/id.Adds a patch changeset for
@medusajs/dashboardto release the fix.Reviewed by Cursor Bugbot for commit 5d71df8. Bugbot is set up for automated code reviews on this repo. Configure here.