side project
Leer en españolprosemirror-react-view
A rewrite of the ProseMirror view layer where React 19 renders the document. It also has a server-rendered reader mode and a way to stream text from an LLM.
What it is
ProseMirror is a toolkit for building rich text editors. I rewrote its view layer so React 19 components render the document, while ProseMirror’s model, state, transform and plugins stay as they are.
The same components render a read-only reader and the editor, and the reader turns into an editor in place when someone starts editing. A separate streaming entry writes text from an LLM into either one. It is a personal project, not published to npm.
How it's built
ProseMirror is a toolkit for rich text editors. I worked on the Atlaskit Editor at Atlassian, which is built on it, and I wanted to know what its view layer would look like if React drew the document. So I rewrote that layer from scratch with React 19 and kept ProseMirror’s model, state, transform and plugin packages as they are. It is a personal project and isn’t published to npm.
highlights
One renderer, editing as a capability
There is one renderer. Editing (input, DOM selection sync, clipboard, composition) and geometry are separate capabilities that attach to a small core through a short list of hooks, each with a reader default. A test builds the source import graph and fails if the rendering code imports editing code, even as a type.
A reader that becomes an editor in place
The reader renders with the editor’s own node, mark and widget components, so the DOM is the same, but it ships no editing code: about 27 KB gzipped against about 47 KB for the full entry, measured on my own code. When editing turns on, the editing chunk loads on demand and attaches after the next commit. No node component remounts, and if you clicked into the text, that point becomes the selection.
Keeping upstream’s EditorView API
The view implements upstream’s EditorView API, so plugins can’t tell the difference: history, keymap, input rules, tables and gapcursor run unmodified. The public types live in contract files, and a compile-only check makes sure the implementation matches them. Input follows the same idea: browser input events are cancelled and turned into transactions through the same props upstream uses, so React stays the only DOM writer.
Tested against upstream, in real browsers
Tests run in Vitest browser mode with Playwright, in Chromium by default and in Firefox and WebKit on request. I ported upstream’s view test scenarios to my own harness. Upstream’s prosemirror-view also runs as an oracle: the same state and transactions go through both views, and the normalised DOM must match after every step.
Benchmarks against upstream
A benchmark mounts the same document in my view and in upstream’s and measures from dispatch until the DOM and selection are committed and laid out, at 1k, 10k and 100k paragraphs. Large documents are split into content-defined chunks, so an insertion only invalidates one chunk, and virtualisation swaps far chunks for a placeholder with their measured height while find-in-page still works.
Streaming LLM text into a document
The streaming entry takes text that arrives over time, usually markdown, and writes it into a reader or an editor. It commits at most one transaction per frame, emits one minimal replace step and re-parses only the last top-level block. When I measured it on a 200-block document, a commit took 0.035 ms against 2.68 ms for re-parsing everything. Your selection, focus and undo history are left alone; the API is still a proposal.
- TypeScript
- React 19
- ProseMirror
- Vitest
- Playwright
- Storybook
- Node (SSR)
- markdown-it