Commit 22077f1
authored
fix(admin): handle null sales channel references in product list and detail views (#15009)
## 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:
```json
{
"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`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 75478bf. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>1 parent 1a5d2e0 commit 22077f1
File tree
3 files changed
+25
-10
lines changed- .changeset
- packages/admin/dashboard/src
- components/table/table-cells/product/sales-channels-cell
- routes/products/product-detail/components/product-sales-channel-section
3 files changed
+25
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
20 | | - | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
24 | | - | |
| 30 | + | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | | - | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | | - | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | | - | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
0 commit comments