Repository navigation
fix(ui): 旧响应不再覆盖新结果(useAsyncBlock 并发保护) - #23
Merged
Merged
Conversation
首屏加载与「重新分析」可能同时在飞,旧实现谁最后回来谁写 data,慢的旧请求会把新结果盖掉。现在每次 load 领序号,只有最新一次允许写回 data / error 并收尾 loading / refreshing。
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.
问题
useAsyncBlock是全站共用的取数封装(app/src/views下 7 个页面/区块共 9 处调用)。区块里同时存在首屏加载(load())与用户点击「重新分析」(load(true)),两个请求可能同时在飞。原实现谁最后回来谁写data:慢的旧请求回来时会把新结果盖掉,页面表现为「点了没反应」;同理,旧请求的失败也会把新结果清成错误态。做法
load领一个序号latestToken;只有最新一次的结果允许写回data/error,并负责收尾loading/refreshing。loading归零)。测试
新增
app/src/composables/__tests__/useAsyncBlock.test.ts:loading/refreshing提前关掉验证
cd app && npx vitest run src/composables/__tests__/useAsyncBlock.test.ts→ 5 passed(修复前 4 failed)cd app && npm test→ 175 passed(新增 1 个测试文件)cd app && npm run lint→ 无输出cd app && npm run build→ 构建通过