chore: 收口 review 执行清单与 runtime 验证
- 补齐 design/10-review 执行清单、验收标准与相关设计治理记录 - 迁移已完成的 tree、mindmap、runtime fallback、AI kernel 等设计和缺陷条目 - 推进 Rust Web runtime、tree/sidebar、page aggregate、mindmap 与 OnlyOffice 路由侧验证支撑 - 增加 task177-task180 smoke/audit 脚本及前端相关测试覆盖
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
import type { SidebarInitialData } from "@/components/sidebar/types";
|
||||
import { buildSidebarDataSyncKey } from "@/components/sidebar/sidebar-sync";
|
||||
import { buildSidebarDataSyncKey, getSidebarDataFreshness } from "@/components/sidebar/sidebar-sync";
|
||||
|
||||
export type PreferredSidebarSnapshotSource = "initial" | "query" | "tree_stream";
|
||||
|
||||
@@ -9,6 +9,7 @@ export function usePreferredSidebarSnapshot(input: {
|
||||
sidebarQueryData: SidebarInitialData | null;
|
||||
treeStreamData: SidebarInitialData | null;
|
||||
treeStreamStatus?: "idle" | "connecting" | "live" | "fallback";
|
||||
treeStreamCursor?: string | null;
|
||||
}) {
|
||||
const querySyncKey = useMemo(
|
||||
() => (input.sidebarQueryData ? buildSidebarDataSyncKey(input.sidebarQueryData) : null),
|
||||
@@ -19,29 +20,40 @@ export function usePreferredSidebarSnapshot(input: {
|
||||
[input.treeStreamData],
|
||||
);
|
||||
const initialSyncKey = useMemo(() => buildSidebarDataSyncKey(input.initialData), [input.initialData]);
|
||||
const initialVersion = useMemo(() => getSidebarDataFreshness(input.initialData), [input.initialData]);
|
||||
const queryVersion = useMemo(
|
||||
() => (input.sidebarQueryData ? getSidebarDataFreshness(input.sidebarQueryData) : null),
|
||||
[input.sidebarQueryData],
|
||||
);
|
||||
const treeStreamVersion = useMemo(
|
||||
() => (input.treeStreamData ? getSidebarDataFreshness(input.treeStreamData) : null),
|
||||
[input.treeStreamData],
|
||||
);
|
||||
const streamIsPreferred = input.treeStreamStatus !== "fallback";
|
||||
const queryHasFreshSnapshot =
|
||||
input.sidebarQueryData != null &&
|
||||
querySyncKey != null &&
|
||||
querySyncKey !== initialSyncKey &&
|
||||
treeStreamSyncKey === initialSyncKey;
|
||||
|
||||
const preferredVersion = Math.max(
|
||||
initialVersion,
|
||||
queryVersion ?? 0,
|
||||
streamIsPreferred ? treeStreamVersion ?? 0 : 0,
|
||||
);
|
||||
const queryHasPreferredVersion = queryVersion != null && queryVersion >= preferredVersion;
|
||||
const treeStreamHasPreferredVersion =
|
||||
streamIsPreferred &&
|
||||
input.treeStreamData != null &&
|
||||
treeStreamVersion != null &&
|
||||
treeStreamVersion >= preferredVersion;
|
||||
|
||||
const source = useMemo<PreferredSidebarSnapshotSource>(() => {
|
||||
if (queryHasFreshSnapshot) {
|
||||
return "query";
|
||||
}
|
||||
if (input.treeStreamData && streamIsPreferred) {
|
||||
if (treeStreamHasPreferredVersion) {
|
||||
return "tree_stream";
|
||||
}
|
||||
if (input.sidebarQueryData) {
|
||||
if (queryHasPreferredVersion) {
|
||||
return "query";
|
||||
}
|
||||
return "initial";
|
||||
}, [
|
||||
input.sidebarQueryData,
|
||||
input.treeStreamData,
|
||||
queryHasFreshSnapshot,
|
||||
streamIsPreferred,
|
||||
queryHasPreferredVersion,
|
||||
treeStreamHasPreferredVersion,
|
||||
]);
|
||||
|
||||
const data =
|
||||
@@ -56,13 +68,22 @@ export function usePreferredSidebarSnapshot(input: {
|
||||
: source === "query"
|
||||
? querySyncKey ?? initialSyncKey
|
||||
: initialSyncKey;
|
||||
const version =
|
||||
source === "tree_stream"
|
||||
? treeStreamVersion ?? initialVersion
|
||||
: source === "query"
|
||||
? queryVersion ?? initialVersion
|
||||
: initialVersion;
|
||||
const cursor = source === "tree_stream" ? input.treeStreamCursor ?? null : null;
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
data,
|
||||
source,
|
||||
syncKey,
|
||||
version,
|
||||
cursor,
|
||||
}),
|
||||
[data, source, syncKey],
|
||||
[cursor, data, source, syncKey, version],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user