修复钱包页面刷新时显示错误余额数据的问题#2749
Conversation
- 移除用户ID检查条件,始终获取最新用户数据 - 确保余额等统计信息准确性 - 解决用户状态更新不及时的问题
WalkthroughThe top-up component's mount useEffect was modified to unconditionally fetch the latest user quota via getUserQuota(). Previously, it only fetched when user.id was absent. The change ensures up-to-date quota information loads every time the component mounts, with a Chinese comment noting the unconditional refresh requirement. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
主要更新: - feat: 磁盘请求体缓存 (QuantumNous#2780) - feat: OpenAI Response API /v1/response/compact (QuantumNous#2644) - feat: 渠道亲和性 (Channel Affinity) (QuantumNous#2669) - feat: Codex渠道支持 (QuantumNous#2652) - feat: Claude/Grok refusal reason显示 - feat: 性能监控和GC控制API - fix: 用户配额获取逻辑 (QuantumNous#2749) - fix: Gemini多工具调用索引问题 - fix: 错误时仍本地计费 冲突解决: - README.md: 保留中文版本 - go.mod: 采用上游较新版本 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
问题现象
在钱包管理页面刷新时,账户的统计数据(当前余额、历史消耗、请求次数)会短暂显示错误的数值或 NaN,随后才恢复正常。
原因分析
TopUp 组件的 useEffect 逻辑中存在优化判断:当检测到 userState?.user?.id 存在时会跳过 getUserQuota() 的 API 调用。 然而,页面刷新时 PageLayout 会优先从 localStorage 加载缓存的用户信息,这份缓存数据往往是过期的或缺少 quota 等动态字段,导致页面渲染了错误的数据。
解决方案
移除了 useEffect 中的条件判断,强制组件在挂载时始终调用 getUserQuota(),确保无论本地缓存状态如何,都能获取并显示最新的用户配额信息。
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.