Compare commits

...
Author SHA1 Message Date
weichen 278b54cf9d Add render/fetch lifecycle logs to cockpit (temporary diagnostics)
Why: scenario 1 hangs at 加载中 with the fetch resolved but the DOM stuck;
lifecycle logs (instance id, effect start, resolve, setProjects, render
state) will locate where the update is lost.

Evidence: tsc green (SELF).

Impact: debug-only logs; removed after diagnosis.
2026-10-17 01:57:02 +00:00
+6 -1
View File
@@ -29,6 +29,7 @@ interface Selection { ref: CockpitNodeRef; parentDocId?: string }
export function DocumentCockpit() {
const identity = useStore(() => store.getIdentityEpoch())
const instanceId = useRef(Math.random().toString(36).slice(2, 8))
const [projects, setProjects] = useState<ProjectView[] | null>(null)
const [pid, setPid] = useState('')
const [filter, setFilter] = useState('')
@@ -63,13 +64,16 @@ export function DocumentCockpit() {
// 项目清单(rdm.project.list:成员可见项目,canAudit 与否不影响文档读取入口)。
useEffect(() => {
let c = false
console.log('[cockpit-dbg] EFFECT start inst=' + instanceId.current, 'identity=', identity)
setProjects(null); setPid(''); setOverview(null); setSelected(null); setFilter(''); setError('')
api.rdmCommand<{ projects?: ProjectView[] } | ProjectView[]>('rdm.project.list')
.then(list => {
const rows = Array.isArray(list) ? list : ((list as any)?.projects ?? [])
console.log('[cockpit-dbg] FETCH resolved inst=' + instanceId.current, 'cancelled=', c, 'rows=', rows.length)
if (!c) return
// rdm.project.list 返回 { projects: [...] };容忍裸数组形态。
const rows = Array.isArray(list) ? list : (list?.projects ?? [])
setProjects(rows)
console.log('[cockpit-dbg] setProjects done inst=' + instanceId.current, 'rows=', rows.length)
})
.catch(e => { if (!c) setError(e.message) })
return () => { c = true }
@@ -116,6 +120,7 @@ export function DocumentCockpit() {
.catch(() => { /* 行内重试入口承担 */ })
}, [pid, filter])
console.log('[cockpit-dbg] RENDER inst=' + instanceId.current, 'identity=', identity, 'projects=', projects === null ? 'null' : projects.length, 'error=', error)
if (error) return <CockpitErrorState raw={error} />
if (!projects) return <div className="empty-note">加载中…</div>
if (projects.length === 0) return <EmptyState icon="folder">暂无可见研发项目——项目成员身份由项目负责人授予</EmptyState>