Design a Rich Text Editor
Problem statement
Design a rich text editor with a structured document model, selection-safe formatting commands, paste sanitization, undo history, autosave, and draft recovery.
Asked In
Key Challenges
- ·Representing a document model without trusting browser HTML as source of truth
- ·Keeping cursor and selection stable across formatting, paste, and rerenders
- ·Undo and redo semantics for typing groups, commands, and async inserts
- ·Safe paste, mention, link, and embed handling without XSS
- ·Large-document performance with accessible keyboard-first editing
2-Minute Answer — High-Level TL;DR
Read this before your interview
HLD Interview Focus
I would keep a structured document model as source of truth and render an editable surface around it. Input, toolbar clicks, shortcuts, paste, and drag-drop all become validated editor commands that update the model, selection, and history transactionally. The UI has a document canvas, floating or fixed format controls, context panels for links and mentions, and autosave status. Browser contenteditable is an input surface, not a trusted data model: pasted HTML is sanitized, schema-normalized, and saved as versioned JSON. The hard parts are selection preservation, IME input, undo grouping, safe embeds, and keeping large documents responsive.
My Approach: Building the Solution
How to think about this problem
I'll start from paste-from-Word corrupting the doc — then design schema, sanitization, commands, and selection stability.
Why This Approach?
Most candidates contentEditable the world. Strong answers put a document model + selection + command history under the React view so paste, undo, and mentions share one pipeline.
Treat the editor like a word processor engine with a React shell, not like a textarea that stores HTML.
Requirements: What Makes a Great Solution?
Clarify scope before designing anything
Requirements Exploration Questions
Ask your interviewer these questions to refine requirements
Which document features are in scope?
- ·Paragraphs, headings, lists, tables, code blocks
- ·Links, mentions, embeds, and images
- ·Markdown shortcuts and slash commands
What editing surface is expected?
- ·Single block note vs multi-page document
- ·Desktop toolbar vs mobile selection toolbar
- ·Plain text export, HTML export, or JSON storage
What correctness rules matter?
- ·Undo granularity
- ·Selection behavior after formatting
- ·IME, paste, drag-drop, and spellcheck support
How is content saved?
- ·Autosave cadence
- ·Draft recovery after refresh
- ·Version conflicts across tabs
What scale and safety limits apply?
- ·Large document size
- ·Untrusted pasted HTML
- ·Allowed URL/embed providers
Functional Requirements
Must Have — MVP
- ✓Editable document surface with block and inline formatting
- ✓Toolbar and keyboard shortcut command paths
- ✓Selection-aware marks, links, and list transforms
- ✓Undo, redo, autosave, loading, and save-error states
- ✓Paste sanitization and schema normalization
- ✓Accessible focus management and status announcements
Advanced (If Time Permits)
- +Slash menu, mentions, tables, images, and embeds
- +Draft recovery from IndexedDB
- +Track changes or comments
- +Optional CRDT adapter for a later collaboration layer
Non-Functional Requirements
Performance Targets
- ·Typing path stays under one frame for normal paragraphs
- ·Toolbar state updates without rerendering the full document
- ·Large documents isolate expensive block rendering
- ·Autosave does not block keystrokes
Reliability & Consistency
- ·Undo history remains coherent across command batches
- ·Save retries use document version to detect conflicts
- ·Selection restores after toolbar and async dialog operations
- ·Local draft recovers after refresh or transient network loss
Accessibility & Input Support
- ·Keyboard-first flows with visible focus and predictable tab order
- ·Screen-reader announcements for async changes using aria-live where appropriate
- ·Reduced-motion alternatives for animated transitions
- ·Pointer, touch, and keyboard parity for every core action
Security & Privacy
- ·Sanitize pasted HTML and generated preview HTML
- ·Allowlist link schemes and embed providers
- ·Do not execute document content as React or raw script
Observability
- ·Track Core Web Vitals plus domain-specific interaction latency
- ·Measure API error rate, retry rate, stale-cache usage, and client exceptions
- ·Emit structured events for critical user journeys and abandoned flows
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Full RADIO-framework walkthrough with architecture diagrams
- Data model, API design, and rendering strategy trade-offs
- Performance, accessibility, and offline sections plus a model answer
Already a member? Log in to open the workspace.