fix(service-party-app): 修复 participants 为 undefined 导致的崩溃

问题:
- 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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-29 11:30:30 -08:00
parent b0a698250d
commit 30ec0a1c8e
2 changed files with 5 additions and 5 deletions

View File

@ -221,7 +221,7 @@ export default function Home() {
<div className={styles.infoRow}>
<span className={styles.infoLabel}></span>
<span className={styles.infoValue}>
{share.metadata.participants.length}
{(share.metadata?.participants || []).length}
</span>
</div>
<div className={styles.infoRow}>

View File

@ -187,10 +187,10 @@ export default function Session() {
{/* 参与方列表 */}
<div className={styles.section}>
<h3 className={styles.sectionTitle}>
({session.participants.length} / {session.threshold.n})
({(session.participants || []).length} / {session.threshold.n})
</h3>
<div className={styles.participantList}>
{session.participants.map((participant, index) => (
{(session.participants || []).map((participant, index) => (
<div key={participant.partyId} className={styles.participant}>
<div className={styles.participantInfo}>
<span className={styles.participantIndex}>#{index + 1}</span>
@ -201,10 +201,10 @@ export default function Session() {
</span>
</div>
))}
{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) => (
<div key={`empty-${index}`} className={`${styles.participant} ${styles.participantEmpty}`}>
<div className={styles.participantInfo}>
<span className={styles.participantIndex}>#{session.participants.length + index + 1}</span>
<span className={styles.participantIndex}>#{(session.participants || []).length + index + 1}</span>
<span className={styles.participantName}>...</span>
</div>
<span className={styles.participantStatus}></span>