修复收藏/聊天记录检索的请求竞态、下载页按钮占一半宽度、两个类名零CSS覆盖

- Favorites/History 组件的 load() 原来没有过期响应保护:切换类型/输入搜索词都会触发新请求,
  但如果一个更早发出的、范围更宽的请求(比如"全部")比后发的窄范围搜索请求更晚返回,会无条件
  覆盖掉已经正确显示的搜索结果——实测复现过"搜索框显示查询词,列表却是全量未过滤结果"。改成
  每次调用 load() 时认领一个自增计数器,响应到达时如果计数器已经被更新的调用推进过,直接丢弃
  这个过期响应。History组件(按topic/tab/query切换)是同一个模式,一并修复。
- `.library-download-actions`(下载页loading/done两态的按钮容器)是2列等宽grid,但两个状态
  永远只渲染1个按钮——按钮固定占左侧50%宽度,右侧约一半容器宽度是死空白。改成单列。
- `.library-empty-hint`(收藏/聊天记录/下载页的加载中提示文字)和`.library-load-more`
  ("加载更多"按钮)在base.css里完全没有对应规则,退化成浏览器默认段落间距/按钮外观——
  补了基础样式,跟第八轮修复的.library-link-text/.library-record-header是同一类遗漏。

均已重新构建并实测验证(下载按钮宽度、空状态文字样式、加载更多按钮样式均用真实DOM测量确认;
请求竞态修复通过真实收藏页搜索/清空往返验证无回归,竞态本身的精确时序难以在测试环境里稳定
复现,但修复采用的是标准、成熟的自增计数器丢弃过期响应模式)。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-09-05 18:46:29 +08:00
co-authored by Claude Sonnet 5
parent 38b43936ce
commit ee2cf6f965
5 changed files with 50 additions and 3 deletions
+14
View File
@@ -220,8 +220,16 @@ function Favorites({view, tinode, onToast}) {
const [hasMore, setHasMore] = React.useState(false);
const [fileUrls, setFileUrls] = React.useState({});
const [sourceNames, setSourceNames] = React.useState({});
// An in-flight request isn't guaranteed to resolve before a newer one its own type/query change
// triggered -- without this, a slow full-list request landing after a fast, narrower search
// response overwrites the correct filtered results with the stale unfiltered ones (confirmed
// live: search box showing a query, list showing all items). Each load() call claims the counter
// for itself; a response only applies if nothing newer has been requested since.
const requestIdRef = React.useRef(0);
const load = React.useCallback((append) => {
const requestId = ++requestIdRef.current;
getFavorites({type, query, cursor: append ? cursor : ''}).then(data => {
if (requestIdRef.current !== requestId) return;
setItems(prev => {
const list = append ? (prev || []).concat(data.items || []) : (data.items || []);
if (!query) writeCachedData('favorites:' + type, list);
@@ -523,12 +531,18 @@ function History({view, hashParams, myUserId, onToast}) {
const [hasMore, setHasMore] = React.useState(false);
const [mediaUrls, setMediaUrls] = React.useState({});
const [senderNames, setSenderNames] = React.useState({});
// Same stale-response guard as Favorites' load() above and for the same reason -- a slower
// request for a since-abandoned topic/tab/query can still resolve after a newer one and
// overwrite its correct results.
const requestIdRef = React.useRef(0);
const load = React.useCallback((append) => {
if (!topic) return;
const requestId = ++requestIdRef.current;
const type = HISTORY_TYPE[view];
const call = view === 'history-search' ? searchTopicMessages(topic, {query, type, cursor: append ? cursor : ''}) :
getTopicMedia(topic, type, append ? cursor : '');
call.then(data => {
if (requestIdRef.current !== requestId) return;
setItems(prev => {
const list = append ? (prev || []).concat(data.items || []) : (data.items || []);
if (!query && cacheKey) writeCachedData(cacheKey, list);