修复 workspace 浏览页初始化后不加载目录#605
Open
sleepinginsummer wants to merge 1 commit intotiann:mainfrom
Open
Conversation
Author
|
已经实际部署验证过,修复之后没问题 |
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]
)
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.
背景
/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 能返回目录数据,修复点限定在前端状态同步逻辑。