Standalone `Editor` loses focus after the first keystroke
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- playwright, react, typescript
- Domain
- frontend
Research direction
Start by tracing the standalone Editor export and use-editable's focus-restoration useLayoutEffect, then compare that path with LiveProvider and LiveEditor. Add an automated regression using the Playwright reproduction: type XYZ into standalone Editor and verify abcXYZ remains focused, while preserving the working LiveEditor behavior.
Written by the indexing model from the issue text.
Description
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)
- Dominant language
- TypeScript
- Stars
- 4.6k
- Forks
- 260
- Avg merge
- 6d 18h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FormidableLabs/react-live
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
FormidableLabs/react-live#419 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
FormidableLabs/react-live#417 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 52/100
FormidableLabs/react-live#413 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
FormidableLabs/react-live#411 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
FormidableLabs/react-live#410 · 1 comment ·
All issues in FormidableLabs/react-live
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mksglu/context-mode#1200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/claude-code#96687 ·
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
AOSSIE-Org/DebateAI#582 · 2 comments ·