fix(suppliers): 主营类目去重,消除 React 重复 key 警告
splitCats 未去重,源数据里同一类目重复登记时(如「游标卡尺;游标卡尺」) 会渲染出两个 key 相同的 chip。React 会因此报 'Encountered two children with the same key',且该行为官方标注为 unsupported。 在 splitCats 出口处按原顺序去重,既消警告也避免卡片上出现重复标签。 由无头浏览器全站巡检发现(供应商页原本有 22 条此类警告)。
This commit is contained in:
@@ -26,10 +26,13 @@ function fmtDate(iso, withTime = true) {
|
||||
}
|
||||
|
||||
function splitCats(text) {
|
||||
return String(text || '')
|
||||
const list = String(text || '')
|
||||
.split(/[、,,;;/|\s]+/)
|
||||
.map((t) => t.trim())
|
||||
.filter(Boolean)
|
||||
/* 源数据里同一类目可能重复登记(如「游标卡尺;游标卡尺」),
|
||||
去重后再渲染,顺带避免 React 因 key 重复而发出警告。 */
|
||||
return [...new Set(list)]
|
||||
}
|
||||
|
||||
/** 从完整地址里抽出省市,卡片上只显示大致方位 */
|
||||
|
||||
Reference in New Issue
Block a user