Repository navigation
nav 后台排序乐观更新重设计(去整表重拉对账) - #30
Merged
todosdev[bot] merged 2 commits intoNov 6, 2026
Merged
Conversation
added 2 commits
November 6, 2026 13:22
三个面板的排序在 store 层同步乐观写入,成功后不再 loadAdmin 整表回拉; 请求串行合并为最新一次,失败回滚并按服务端刷新一次。loadAdmin 用本地 顺序投影,避免旧响应盖回新顺序。 Checkpoint: 3fww-3NsvyNQ5V4lnPthN
成功发送后仅在本轮无待发顺序时才更新 localIds,避免连拖时旧顺序被当成本地权威 并经补发写回服务端;resetAdminOrderState 加会话世代号,旧会话在飞循环落地后静默 退出,不再并发开循环、回滚新会话或清掉新循环的 running。补 4 条回归用例。 Checkpoint: C1MANOQX3wE8PVmVH1Xb6
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.
Summary
loadAdmin()整表重拉,消除松手回弹与约 2 秒延迟。Changes
web/src/lib/nav-store.ts(核心)reorderCategories/reorderLinks/reorderEngines三个乐观排序动作,配一套排序簿记(localIds/pendingIds/beforeIds/running);applyOrder统一负责重排并重写sortOrder(链接面板按sortOrder渲染,只换数组顺序不够)。sort_order停在默认 0 导致刷新后跳位。UPDATE、无事务,可能已部分生效),错误抛给面板提示。loadAdmin()增加projectLocalOrder投影,挡住「排序前发出、排序后落地」的旧响应;会话结束(登出 / 401 / 探活失败)时清空簿记并递增sessionEpoch,让旧会话仍在飞的循环落地后静默退出(不写 store、不回滚新会话、不清新循环的running)。web/src/components/admin/crud-panels.tsx、settings-panels.tsxreorder改走 store 动作,成功后不再调用onChanged();失败toast.error("排序失败,已恢复原顺序")。链接面板「按分类过滤时重建全局 ids」的语义与代码未改,乐观写入作用在全量 links 上。其余 CRUD 的onChanged()全部保留。测试
web/test/deferred.ts(手控 Promise,用于「请求还在飞」时断言)与web/test/nav-store-reorder.test.ts(15 条:乐观即时、成功不重拉、连拖合并、失败回滚、连拖期间插入loadAdmin、新增实体补发、会话切换三条)。web/test/crud-panels.test.tsx补 4 条面板用例(三面板即时生效且onChanged0 次、失败回滚提示、链接过滤视图提交全局 ids)。未改动:worker、
docs/api-contract.md、依赖清单、sortable-list.tsx拖拽交互。Testing
pnpm lint(29 条基线告警,改动文件 0 新增)、pnpm format:check、pnpm typecheck、pnpm test(worker 155 / web 136)、pnpm build—— 全绿。localIds守卫」「loadAdmin投影」「失败回滚」「落地补发」「会话世代号(成功 / 失败 / finally 三处)」,每次恰好打掉一条对应用例,确认用例不是空转。Fetch在 Request 阶段挂起 reorder):三面板松手即刻定住、挂起 800ms 无回弹;连续拖拽时只有一个在飞请求,第二个携带最新顺序;失败请求回滚并出现提示、服务端顺序不变;链接面板「按分类过滤」提交全局 ids、跨分类相对顺序不变;刷新后顺序与服务端一致(含「排序在飞时新建分类」的场景)。