From 30ec0a1c8e106282a29ced698072f1a0241e4e3e Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 29 Dec 2025 11:30:30 -0800 Subject: [PATCH] =?UTF-8?q?fix(service-party-app):=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?participants=20=E4=B8=BA=20undefined=20=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - Session.tsx 和 Home.tsx 直接访问 participants.length - 当后端返回的 session 数据中 participants 为 undefined 时崩溃 - 导致 TypeError: Cannot read properties of undefined (reading length) 修复: - 添加空值检查 (session.participants || []).length - 使用 Math.max(0, ...) 防止负数长度 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 --- .../services/service-party-app/src/pages/Home.tsx | 2 +- .../services/service-party-app/src/pages/Session.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/mpc-system/services/service-party-app/src/pages/Home.tsx b/backend/mpc-system/services/service-party-app/src/pages/Home.tsx index 57a0ebec..504964d5 100644 --- a/backend/mpc-system/services/service-party-app/src/pages/Home.tsx +++ b/backend/mpc-system/services/service-party-app/src/pages/Home.tsx @@ -221,7 +221,7 @@ export default function Home() {
参与方 - {share.metadata.participants.length} 人 + {(share.metadata?.participants || []).length} 人
diff --git a/backend/mpc-system/services/service-party-app/src/pages/Session.tsx b/backend/mpc-system/services/service-party-app/src/pages/Session.tsx index 84c70734..a8fc8454 100644 --- a/backend/mpc-system/services/service-party-app/src/pages/Session.tsx +++ b/backend/mpc-system/services/service-party-app/src/pages/Session.tsx @@ -187,10 +187,10 @@ export default function Session() { {/* 参与方列表 */}

- 参与方 ({session.participants.length} / {session.threshold.n}) + 参与方 ({(session.participants || []).length} / {session.threshold.n})

- {session.participants.map((participant, index) => ( + {(session.participants || []).map((participant, index) => (
#{index + 1} @@ -201,10 +201,10 @@ export default function Session() {
))} - {Array.from({ length: session.threshold.n - session.participants.length }).map((_, index) => ( + {Array.from({ length: Math.max(0, session.threshold.n - (session.participants || []).length) }).map((_, index) => (
- #{session.participants.length + index + 1} + #{(session.participants || []).length + index + 1} 等待加入...