Standalone `Editor` loses focus after the first keystroke
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- playwright, react, typescript
- 领域
- frontend
调研方向
首先跟踪 standalone Editor 的导出以及 use-editable 用于恢复焦点的 useLayoutEffect,然后将这条路径与 LiveProvider 和 LiveEditor 进行比较。使用 Playwright reproduction 添加自动化回归测试:在 standalone Editor 中输入 XYZ,并验证 abcXYZ 仍保持焦点,同时保留正常工作的 LiveEditor 行为。
由索引模型根据 Issue 内容生成。
描述
Summary
The exported Editor component loses DOM focus after the first keystroke when used standalone. Only one character can be typed; subsequent keystrokes are discarded until the user clicks back into the editor.
LiveProvider + LiveEditor is unaffected, so this only bites consumers using the standalone Editor export.
Version
react-live@4.1.8 (reproduced against the published package, not a local build).
Reproduction
import { Editor } from "react-live";
<Editor code="abc" language="javascript" onChange={() => {}} />;
Click at the end of the text and type XYZ.
Expected: abcXYZ
Actual: abcX, and document.activeElement is <body>
Automated reproduction
Driving the above page with Playwright:
| case | typed | result | document.activeElement |
|---|---|---|---|
<Editor> standalone |
XYZ |
abcX |
BODY |
<LiveProvider> + <LiveEditor> |
XYZ |
abcXYZ |
PRE |
Same outcome with 30ms and 250ms between keystrokes, and still BODY after a 1.5s pause.
A human tester saw a slightly different variant — two characters landed, then typing became possible again after a pause — so the exact cut-off may be timing dependent, but the first keystroke reliably drops focus.
Notes from debugging
- The
<pre>element is not replaced: it is the same node before and after (sameNode: true,isConnected: true). - A real
blurevent fires on it. - Calling
.focus()on the same element afterwards restores normal typing, so the component is otherwise healthy. use-editablerestores focus in auseLayoutEffect, but only when it has a recorded position (if (e.position) { a.focus(); ... }).- The working
LiveProviderpath produces an extra re-render when its async transpile resolves, which appears to be what re-runs that layout effect. StandaloneEditorhas no such second render.
This suggests the standalone case depends on a re-render it does not reliably get, rather than the blur itself being intentional.
Related
- #409 (pasting a newline moves the cursor incorrectly)
- #390 (keyboard accessibility / moving focus out of the editor)
- 主要语言
- TypeScript
- 星标
- 4.6k
- 派生
- 260
- 平均合并
- 6 天 18 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
FormidableLabs/react-live 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 55/100
FormidableLabs/react-live#419 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 48/100
FormidableLabs/react-live#417 ·
-
bug
难度 3/5 1-2 天 新手友好度 52/100
FormidableLabs/react-live#413 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
FormidableLabs/react-live#411 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
FormidableLabs/react-live#410 · 1 条评论 ·
查看 FormidableLabs/react-live 的全部 Issue
相似的 Issue
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
-
Crush 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
catppuccin/catppuccin#3125 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
ElementsProject/cln-application#167 · 1 条评论 · 1 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Quantco/pnpm-licenses#17 ·
-
难度 2/5 1-3 小时 新手友好度 75/100