Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Standalone `Editor` loses focus after the first keystroke

未关闭
#415 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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 内容生成。

描述

bug
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 blur event fires on it.
  • Calling .focus() on the same element afterwards restores normal typing, so the component is otherwise healthy.
  • use-editable restores focus in a useLayoutEffect, but only when it has a recorded position (if (e.position) { a.focus(); ... }).
  • The working LiveProvider path produces an extra re-render when its async transpile resolves, which appears to be what re-runs that layout effect. Standalone Editor has 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

FormidableLabs/react-live 的其他 Issue

查看 FormidableLabs/react-live 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。