fix(scratch-pad): 修复空格无法输入和换行被吞的 content 同步循环#461
Merged
Conversation
将 content 从 useEffect deps 移除,引入 contentRef 访问最新值。 根因:useEffect 包含 content 依赖,每次用户输入都会触发 editor.commands.setContent() 调用,ProseMirror DOMParser 规范化 HTML 时会吞掉尾部空格和空段落,并重置光标位置。 修复后 useEffect 仅在 loaded/editor 变化(初始加载/Tab 重新挂载) 时同步内容,用户输入不再触发 setContent,消除死循环。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
问题
ScratchPad 编辑器存在两个输入异常:
根因分析
useEffect将contentatom 加入依赖数组,导致以下死循环:修复方案
content从useEffect依赖数组移除contentRef追踪最新内容值(避免 stale closure)editor.getHTML() !== latestContent比对,只在内容真正不同时调用setContentuseEffect现在只在loaded/editor变化时触发(初始加载 + Tab 重新挂载),用户输入不再触发setContent,消除循环。测试
🤖 Generated with Claude Code