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:
parent
b0a698250d
commit
30ec0a1c8e
|
|
@ -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}>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue