fix: guard suggestion rendering and preserve input text injection#94
Merged
Conversation
Agent-Logs-Url: https://github.com/DevCloudFE/matechat-react/sessions/5308a157-6654-4ac6-ae98-dad100845160 Co-authored-by: fu050409 <46275354+fu050409@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix suggestion injection bug and prevent empty suggestion panel rendering
fix: guard suggestion rendering and preserve input text injection
May 12, 2026
fu050409
approved these changes
May 12, 2026
Contributor
Workspace change through: 361506f5 changesets found Planned changes to release
|
This was referenced May 12, 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.
Two related bugs in
Suggestion: selecting an item could silently corrupt user input, and the panel's container div rendered unconditionally regardless of trigger state.Root causes
onInject(newText, context?.triggerIndex ?? -1)— the-1fallback reachedprevMessage.slice(0, -1)downstream, stripping the last character on every suggestion selection when no context was active.sender.tsxand always rendered, leaving a white floating box above the textarea even with no active trigger.Changes
src/suggestion.tsxnullearly whenuseSuggestionContextreturnsnull— cuts off both the empty panel and the corrupt-injection path in one guard.context.triggerIndexdirectly (no?? -1); context is guaranteed non-null past the guard.Suggestionso the component fully owns its DOM presence.src/sender.tsx<div>—Suggestionrenders nothing when inactive, so the container no longer needs to live in the parent..changes/fix-suggestion-injection.md—patch:fixchangeset entry.Original prompt
Create the next pull request in
DevCloudFE/matechat-reactto fix the suggestion injection bug and the unwanted empty suggestion panel rendering.Scope:
src/suggestion.tsx.src/sender.tsxonly if needed to correctly conditionally render the suggestion container or integrate the fix cleanly..changes/for this PR usingpatch:fix.Required fixes:
triggerIndexto-1.onInject(newText, context?.triggerIndex ?? -1).contextis null, downstream slicing withslice(0, -1)can silently delete the last character of the user's input.contextis null, causing an empty floating panel in the UI.Suggestionreturnsnullwhen no context exists), and update parent conditional rendering if necessary.Changes file requirements:
.changes/for this PR.Suggested PR title:
fix: guard suggestion rendering and preserve input text injectionAcceptance criteria:
-1trigger index..changes/*file is added withpatch:fix.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: 深度阅读src/在新版的项目代码,审查可能的脆弱性、漏洞和使用体验问题
Assistant: 请提供明确的仓库信息(
owner/repo),我就可以开始深度审查src/目录在“新版”代码中的脆弱性、安全漏洞和使用体验问题。如果你方便,也请一并给我以下任一信息,以便我直接定位“新版”:
main、develop、release/v2你可以直接回复例如:
owner/repo: octo-org/my-app,分支: main请审查 https://github.com/octo-org/my-app/tree/main/src拿到仓库后,我会:
src/User: 在matechat-react里
Assistant: 我正在等待你对深度审查请求的确认,一旦你接受,我就继续读取并审查
DevCloudFE/matechat-react的src/目录。User: @copilot Accepted Confirmation: Are you sure?
Assistant: 已开始对
DevCloudFE/matechat-react的src/进行深度审查。你可以通过下面的任务链接跟踪进度:
任务完成后,我会基于实际代码证据给出按严重级别分类的问题清单,以及修复建议和 Top 5 优先修复项。
User: 你能够看到任务执行结果吗,可以的话生成多个任务来针对每一个修复项进行修复和pr。执行审查的Agent报告无法推送多个分支来创建pr。
Assistant: 可以,但我现在还看不到那个深度审查任务的详细执行结果内容,至少在当前对话里还没有自动返回报告正文。
不过你这个目标我可以支持,方式是:
先拿到审查结果
你把审查 Agent 的结论贴给我,或者把任务结果链接里可见的报告内容发我。
我再把问题拆成多个独立修复任务
我会按“一个问题/一类问题一个 PR”的方式拆分,避免耦合,方便审阅和回滚。
然后我可以逐个为每个修复项创建 PR
前提是你对每个 PR 明确指定:
DevCloudFE/matechat-reactmain需要注意一件事:
我不能直接“基于那个深度研究任务自动批量派生多个 PR”,因为深度研究工具本身只负责调研,不直接暴露成可让我批量消费的结构化修复队列;而创建 PR 需要我针对每个修复项单独发起一次 PR 创建任务。
如果你想现在就开始,最省事的方式是直接给我以下任一项:
方案 A:贴审查结果
把审查报告贴过来,我会直接输出:
方案 B:让我先做“修复任务拆分”
如果你不方便贴报告,我也可以基于你的原始目标,先给出一个建议拆分,例如:
但这只是“预拆分”,不如基于真实审查结果准确。
如果你要我直接开始创建多个 PR
请按这个格式回复我:
DevCloudFE/matechat-reactmain(或你的实际分支)粘贴内容为每个修复项分别创建 PR如果你愿意,我下一条就可以先帮你把“常见审查结论”整理成一个适合批量开 PR 的修复任务清单模板。
User: ```
深度代码审查报告:DevCloudFE/matechat-react (src/)
一、脆弱性与稳定性风险
🔴 Critical
C-1:src/suggestion.tsx — triggerIndex 默认值 -1 导致文本注入逻辑错误
位置:src/suggestion.tsx:73-75,src/sender.tsx:132-134
现象:
TSX
// suggestion.tsx:73-75
onInject(newText, context?.triggerIndex ?? -1);
当 context 为 null(没有触发词时),triggerIndex 回退到 -1。随后在 sender.tsx 的 handleTextInject 中:
TSX
const textBefore = prevMessage.slice(0, suggestionStartPosition); // slice(0, -1) → 截掉最后一个字符
const textAfter = prevMessage.slice(currentCaretPosition);
slice(0, -1) 会截去消息末尾最后一个字符,使得用户每次从建议列表选择时都会静默删除最后一字。
风险:静默数据损坏,用户无感知地丢失输入内容。
触发条件:用户点击/选择建议列表中的项目,且 context 为 null(这只有在 List 未被条件渲染的情况下才可触发,与下一个问题关联)。
修复建议:在 Suggestion 组件中,当 context 为 null 时不渲染 List(if (!context) return null),彻底切断该路径。
🔴 Critical
C-2:src/bubble/markdown.tsx — Link 组件未过滤 javascript: href,...
This pull request was created from Copilot chat.