修复 workspace 浏览页初始化后不加载目录#605
Conversation
|
已经实际部署验证过,修复之后没问题 |
There was a problem hiding this comment.
Findings
- [Major]
workspaceRoots的空数组 fallback 会触发无限重置 —workspaceRoots在selectedMachine?.metadata?.workspaceRoots为空时每次 render 都会创建新的[],而这个 effect 现在依赖它并且每次都会setEntries([])写入新的数组状态。选择一台未配置 workspace roots 的机器,或机器数据尚未加载到 roots 时,effect 会 render -> 新workspaceRoots引用 ->setEntries([])-> render 循环,导致/browse空态也可能卡死。证据:web/src/components/WorkspaceBrowser.tsx:236
Suggested fix:const workspaceRoots = useMemo( () => selectedMachine?.metadata?.workspaceRoots ?? [], [selectedMachine?.metadata?.workspaceRoots] )
Summary
- Review mode: initial
- 发现 1 个需要修复的问题,集中在本次修改后的 effect 依赖。
Testing
- Not run (automation)
| setEntries([]) | ||
| setError(null) | ||
| }, [machineId]) | ||
| }, [machineId, workspaceRoots]) |
There was a problem hiding this comment.
[Major] workspaceRoots 在没有 roots 时来自 selectedMachine?.metadata?.workspaceRoots ?? [],每次 render 都会得到新的空数组引用。这个 effect 现在依赖它,并且无条件 setEntries([]) 写入新的数组状态,所以未配置 workspace roots 或 roots 尚未加载时会进入 render 循环,/browse 的空态也可能卡死。
Suggested fix:
const workspaceRoots = useMemo(
() => selectedMachine?.metadata?.workspaceRoots ?? [],
[selectedMachine?.metadata?.workspaceRoots]
)| setEntries([]) | ||
| setError(null) | ||
| }, [machineId]) | ||
| }, [machineId, workspaceRoots]) |
There was a problem hiding this comment.
[MAJOR] workspaceRoots should not be part of this reset trigger. useSSE replaces machine objects on normal sync updates, so this effect can clear currentPath, entries, and error while the user is still browsing the same machine. The root-selection effect above already reacts to root changes, so keep this reset tied to machineId only.\n\nSuggested fix:\ntsx\nuseEffect(() => {\n setSelectedRoot(workspaceRoots[0] ?? null)\n setCurrentPath(null)\n setEntries([])\n setError(null)\n}, [machineId])\n
There was a problem hiding this comment.
Review mode: initial
No issues found in the changed lines. The fix matches the existing machine/root sync flow and I did not find a regression in selection or auto-load behavior.
Testing: Not run (review only). Residual risk: WorkspaceBrowser still has no direct automated coverage, so the root-selection path remains untested.
背景
/browse页面在 runner 已经通过--workspace-root上报 workspace roots 的情况下,仍可能停留在「No subdirectories found / 未找到子目录」空态。实际排查时,后端
list-directoryRPC 能正常返回目录列表,机器 metadata 中也包含正确的workspaceRoots,问题发生在前端WorkspaceBrowser的状态初始化流程。问题原因
WorkspaceBrowser中有两个 effect 会同时影响浏览根目录状态:workspaceRoots设置selectedRoot。machineId变化时重置视图,并把selectedRoot清空。当机器数据加载或切换机器时,后一个重置逻辑可能把刚设置好的
selectedRoot清掉,导致自动加载目录的 effect 因selectedRoot为空而直接返回。最终 UI 没有currentPath,也没有触发list-directory,只显示空态。修复内容
切换机器时不再把
selectedRoot置空,而是同步设置为当前机器的第一个workspaceRoot,同时保留清空currentPath、entries和error的重置行为。这样自动加载 effect 可以继续以新的 root 作为入口请求目录,避免页面卡在空态。
验证
bun run typecheck:web通过。bun run build:web通过。list-directory对同一 workspace root 能返回目录数据,修复点限定在前端状态同步逻辑。