From 33e0f50238ff7b1798b8955be8203f11e792e4e4 Mon Sep 17 00:00:00 2001 From: Dwindi Ramadhana Date: Tue, 30 Dec 2025 17:06:58 +0700 Subject: [PATCH] fix: Add fallback keys to taxonomy list rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: React warning about missing keys persisted despite keys being present. Root cause: term_id/attribute_id could be undefined during initial render before API response. Solution: Add fallback keys using array index when primary ID is undefined: - Categories: key={category.term_id || `category-${index}`} - Tags: key={tag.term_id || `tag-${index}`} - Attributes: key={attribute.attribute_id || `attribute-${index}`} This ensures React always has a valid key, even during the brief moment when data is loading or if the API returns malformed data. Files Modified: - admin-spa/src/routes/Products/Categories.tsx - admin-spa/src/routes/Products/Tags.tsx - admin-spa/src/routes/Products/Attributes.tsx Result: ✅ React key warnings should be resolved ✅ Graceful handling of edge cases where IDs might be missing --- admin-spa/src/routes/Products/Attributes.tsx | 4 ++-- admin-spa/src/routes/Products/Categories.tsx | 4 ++-- admin-spa/src/routes/Products/Tags.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/admin-spa/src/routes/Products/Attributes.tsx b/admin-spa/src/routes/Products/Attributes.tsx index 5046c99..6b8683f 100644 --- a/admin-spa/src/routes/Products/Attributes.tsx +++ b/admin-spa/src/routes/Products/Attributes.tsx @@ -164,8 +164,8 @@ export default function ProductAttributes() { - {filteredAttributes.map((attribute) => ( - + {filteredAttributes.map((attribute, index) => ( + {attribute.attribute_label} {attribute.attribute_name} {attribute.attribute_type} diff --git a/admin-spa/src/routes/Products/Categories.tsx b/admin-spa/src/routes/Products/Categories.tsx index 7df087b..a2570ec 100644 --- a/admin-spa/src/routes/Products/Categories.tsx +++ b/admin-spa/src/routes/Products/Categories.tsx @@ -155,8 +155,8 @@ export default function ProductCategories() { - {filteredCategories.map((category) => ( - + {filteredCategories.map((category, index) => ( + {category.name} {category.slug} diff --git a/admin-spa/src/routes/Products/Tags.tsx b/admin-spa/src/routes/Products/Tags.tsx index f576c66..d9435ff 100644 --- a/admin-spa/src/routes/Products/Tags.tsx +++ b/admin-spa/src/routes/Products/Tags.tsx @@ -153,8 +153,8 @@ export default function ProductTags() { - {filteredTags.map((tag) => ( - + {filteredTags.map((tag, index) => ( + {tag.name} {tag.slug}