fix: hooks violation in custom agent creation#585
Merged
yaozheng-fang merged 2 commits intoJun 5, 2026
Conversation
yaozheng-fang
approved these changes
Jun 5, 2026
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.
问题描述
在"添加 Agent" -> "从 0 快速创建" -> "自定义"流程中,填写完信息后点击"生成项目"按钮,页面突然变白屏,控制台报错:
Error: Minified React error #300
Uncaught Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement.
问题定位
根因:违反了 React Hooks 规则(Hooks 必须在所有条件判断之前调用)
在
CustomCreate.tsx中:if (project)条件判断并提前返回预览模式sectionImpl的useRef声明在条件返回之后当用户点击"生成项目"触发
setProject(proj)后:project = null,执行所有 hooks(数量 = N)project !== null,在第 1046 行提前返回,跳过后续 hooks(数量 = N-1)React 检测到 hooks 数量不一致,抛出错误导致白屏。
解决方案
sectionImpl useRef移至组件顶部(第 888 行),在所有条件返回之前声明测试结果
✅ 开发环境验证通过:
影响范围
frontend/src/create/CustomCreate.tsx、frontend/src/ui/ProjectPreview.tsx