fix(maa): 用户配置页在缺少分服关卡数据时不再整页崩溃 - #618
Open
qiyinxi wants to merge 1 commit into
Open
Conversation
loadActivityStageOptions 把 overview.StageByServer 无条件赋给
stageOverviewByServer,字段缺席时 ref 被抹成 undefined,把 234 行特意给的
{} 默认值也一起抹掉;紧接着 applyServerStageOptions 里的
`if (!stageOverview) return` 只防住「某服务器没有条目」,防不住「容器本身没了」,
于是上一行 stageOverviewByServer.value[server] 先抛 TypeError。
该函数由服务器切换的 watcher 触发,loadUserData 填表期间就会跑到,
所以表现为打开页面即整页渲染失败。
改为缺字段时给出可读提示并保留原有数据,不再写入 undefined;断言类型同时
放宽成 Partial<...> | undefined,让 TS 强制这次判空——后端 InfoOut.data 是
Dict[str, Any],该字段不进 schema,原来的断言提供不了任何保护。
Closes AUTO-MAS-Project#614
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
审查者指南(在较小的 PR 中折叠显示)审查者指南该 PR 针对省略 安全加载活动阶段的时序图sequenceDiagram
participant User
participant MAAUserEdit
participant Backend
participant Logger
participant ActivityStageError
User->>MAAUserEdit: loadActivityStageOptions()
MAAUserEdit->>Backend: 加载概览数据
Backend-->>MAAUserEdit: response.data
alt StageByServer 存在
MAAUserEdit->>MAAUserEdit: stageOverviewByServer.value = overview.StageByServer
MAAUserEdit->>MAAUserEdit: applyServerStageOptions()
else StageByServer 缺失
MAAUserEdit->>Logger: error()
MAAUserEdit->>ActivityStageError: 设置阶段缺失错误
MAAUserEdit-->>User: 保留现有阶段数据并显示失败信息
end
文件级变更
可能关联的问题
提示和命令与 Sourcery 交互
自定义你的体验访问你的仪表板以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR hardens activity-stage loading against responses that omit Sequence diagram for safe activity-stage loadingsequenceDiagram
participant User
participant MAAUserEdit
participant Backend
participant Logger
participant ActivityStageError
User->>MAAUserEdit: loadActivityStageOptions()
MAAUserEdit->>Backend: load overview data
Backend-->>MAAUserEdit: response.data
alt StageByServer is present
MAAUserEdit->>MAAUserEdit: stageOverviewByServer.value = overview.StageByServer
MAAUserEdit->>MAAUserEdit: applyServerStageOptions()
else StageByServer is missing
MAAUserEdit->>Logger: error()
MAAUserEdit->>ActivityStageError: set missing-stage error
MAAUserEdit-->>User: preserve existing stage data and show failure
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #614
问题
TypeError: Cannot read properties of undefined (reading 'Official')(SentryAUTO-MAS-DESKTOP-W),MAA 用户配置页打开即整页渲染失败。loadActivityStageOptions把overview.StageByServer无条件赋给stageOverviewByServer:234 行
ref<HomeOverviewResponse['StageByServer']>({})特意给的{}默认值因此被抹掉。紧接着applyServerStageOptions里:那道
if只防住「某个服务器没有条目」,防不住「容器本身没了」。而applyServerStageOptions由 1259 行服务器切换的 watcher 触发,loadUserData填表期间就会跑到——所以是打开页面即崩,不是点某个按钮才崩。852 行的
as HomeOverviewResponse是无校验断言:后端InfoOut.data声明为Dict[str, Any],StageByServer不进 schema,生成的 API 类型里也没有这个字段,TS 在这里提供不了任何保护。改动
三点:
undefined,{}默认值得以保留,watcher 后续再跑也只会安全地走return;Partial<...> | undefined,让 TS 强制这次判空,而不是靠人记得;关于触发条件
字段为何缺席未验证。后端
app/api/info.py:286在 200 路径上总会带上它(InfoOut.data是Dict[str, Any],不会被 response_model 裁掉),500 路径又已被response.code !== 200提前拦掉。最可能是后端目录没跟前端一起更新,即 #544 那个非原子部署留下的混版安装。但触发条件在外部不影响这一行该自守——所以本 PR 只修前端这一侧,没有去动后端。
本地验证
那条失败是
electron/services/backendService.test.ts > managed 模式 > 不传 --repo、不先跑 environment ensure,--app-root 就是用户数据根。已确认是 dev 上的既有失败:把本次改动 stash 掉后在干净的upstream/dev上重跑,同一条同样失败(1 failed | 413 passed),与本 PR 无关。yarn format会顺带重排 ZZZ-OD 那批尚未格式化的文件,本 PR 已把它们全部还原,diff 只有 MAAUserEdit.vue 一个文件。没有做真机手测:复现需要一个
StageByServer缺席的后端,本地起的开发后端总会返回该字段。请审阅
@DLmaster361 这个页面主要是你写的。确认后请你自行合并,我不代合。
Sourcery 摘要
在 MAA 用户配置页面中安全处理缺失的活动阶段数据。
错误修复:
StageByServer字段时,防止 MAA 用户配置页面崩溃。Original summary in English
Summary by Sourcery
Handle missing activity stage data safely in the MAA user configuration page.
Bug Fixes: