Overview
When to use
- The page shows a Document saved by
RichTextEditor: an article, a description, a policy. - You need the component in a server component, or where pulling in Tiptap just to read is not acceptable.
When not to use
- The HTML came from a user and the server has not sanitized it — sanitize first (section "Sanitization on the consumer's server"), then show. The component puts everything it receives into the page.
- For editing, use
RichTextEditor. ItsreadOnlykeeps the engine alive for text that does not change; for a page that only displays the Document, useRichTextView. - Arbitrary HTML outside the Schema (
styleother than the author's color,thead,caption, images withoutfigure): the typography is built for the Schema's tags, and anything else looks like the browser default. - For short single-line text, use
Text.
Minimal example
In Next.js, the @olddevs/ui/editor entry point must be listed in optimizePackageImports on its own line (getting-started.md): otherwise the whole Editor with its engine ships to the browser along with the View — 435 kB of First Load JS instead of 137 kB.
// Server component: no directive needed.
import { RichTextView } from "@olddevs/ui/editor";
export default async function ArticlePage({ id }: { id: string }) {
const article = await loadArticle(id); // article.html was sanitized on save
return <RichTextView html={article.html} className="max-w-prose" />;
}Public API
html— the saved Document, an HTML string. Not sanitized: it goes into the markup throughdangerouslySetInnerHTMLas is. An empty string renders an empty container.className— added after the typography classes and can override them.surface—"theme"(default) or"paper": Paper, a light area in any theme, see "Surface". The type isRichTextSurface.tools— the Document's own Tools, the same array as forRichTextEditorandsanitizeRichText. The View reads from it the Islands of custom Blocks (blocks[name].island, typeCustomIslandProps), the formula optionstool("mathematics", { macros })and the video optiontool("youtube", { autoload })(section "Video"); withouttoolsthe View stays as before (section "Custom Block's Island").- Everything else is regular
divprops:id,aria-*,data-*,ref.childrenanddangerouslySetInnerHTMLare not accepted. highlightCodeBlocks(html)— server-side highlighting of code blocks, the@olddevs/ui/editor/highlightentry point (section "Code block highlighting").RichTextViewhas no prop for this, on purpose.sanitizeRichText(html, purify, toolsOrOptions?)sanitizes HTML against the Schema using the consumer's DOMPurify instance (RichTextPurifier). Pass the Editor'stoolsarray or aRichTextSanitizeOptionsobject withtoolsandallowRelativeLinks. The hook event type isRichTextAttributeHookEvent.isAllowedLinkHref(href, options?)checks a single link destination using the same policy. TheRichTextLinkOptionsargument supportsallowRelativeLinks, which defaults tofalse.richTextSchema(tools?)— the Schema as data for a set oftools: theRICH_TEXT_SCHEMAfields pluscustomBlocksandcustomMarks— the rules of custom Blocks and Marks (RichTextCustomBlockRules,RichTextCustomMarkRules). The type isRichTextSchema. TheRICH_TEXT_SCHEMAconstant itself is still the kit's Schema.richTextSanitizeConfig()— a restrictive sanitizing config for DOMPurify without hooks: safe on its own, but it loses part of the Editor's markup. The type isRichTextSanitizeConfig.sanitizeRichText,isAllowedLinkHref,richTextSchemaandrichTextSanitizeConfigare data and functions only, with no dependencies; they are safe in a server module. The lightweight entry point is@olddevs/ui/editor/schema; they are also available from@olddevs/ui/editor.
The typography comes from the same src/editor/styles/prose.ts module that attaches classes to the Editor's content, so text looks the same in the Editor and on the page. The classes sit on the container and find tags by name, so the Document's HTML has no classes or style. Colors come from the kit's tokens, and the dark, light and dim themes switch on their own. A separate Tailwind @source is not needed: the line from getting-started.md covers the classes.
Paper: surface
surface="paper" is Paper, a light area in any app theme, like RichTextEditor: text, links, palettes, highlights, tables, captions and code blocks (GitHub Light) look as in the light theme, and Paper is set off from the page by the app theme's border and shadow. By default ("theme") the Document follows the app theme and does not set a background.
<RichTextView html={cleanHtml} surface="paper" />When to use Paper: a print or PDF preview, displaying an email or a document that will leave the app in its light look. A Document that is only read inside the app stays on "theme". Everything around Paper — page headings, buttons, menus — stays in the app theme: Paper covers only the RichTextView container.
The component stays a server component: Paper is classes and attributes on the container (data-theme="light", data-surface="paper"), with no style and no client code. The same Document on the Paper looks identical in the Editor and here — a test checks this.
Accessibility
The component adds no roles: it is a regular div with semantic HTML inside — headings, lists, a quote. A Details Block is a native details and summary: opening from the keyboard (Tab, Enter, Space) and announcing the state are the browser's job. The Document's headings start with H2 if the Editor worked without heading1: the page keeps the H1 itself. A Document with heading1 contains its own h1, and then the page does not put in a second one. An H1 in RichTextView is styled with the same typography as in the Editor. If the Document is a separate area of the page, give the container a name through aria-label and role="region".
Anti-patterns
- Putting a string into
htmlthat has not passed server-side sanitizing. - Sanitizing only in the browser before sending: the server does not see it.
- Using
RichTextEditor readOnlyfor a page that only displays the Document: a 295–339 kB gzip engine just to display text (size table). - Adding
"use client"to a file whereRichTextViewis the only component: it is not needed and pulls its neighbors into the client graph (the Island with the "Copy" button is a separate file with its own directive, andRichTextViewalready has it). - Passing a server component or a function with a dynamic import to
island: only a reference to a client component from a module with"use client"crosses the RSC boundary. - Building your own copy button on top of
RichTextViewor reading text from the Block's DOM: the header and the button are already there, and what gets copied is the code'stextContent, not the markup.
Links
- Source:
src/editor/RichTextView.tsx; header and button —src/editor/features/code/codeHeader.ts(header markup),src/editor/features/code/CodeCopyIsland.tsx(client Island),src/editor/features/code/CodeCopyButton.tsx; the Island of a custom Block —src/editor/core/viewIsland.ts(choosing Islands by the Document),src/editor/ui/BlockIsland.tsxandsrc/editor/ui/BlockIslandSlots.tsx(client Island); Paper (surface="paper") —src/editor/styles/surface.tsandsrc/editor/styles/tokens.ts; typography —src/editor/styles/prose.ts, highlight theme —src/editor/styles/codeTheme.ts; server highlighting —src/editor/features/code/highlight.ts, entry point —src/editor/highlight-entry.ts; the Schema as data,sanitizeRichTextand the sanitizing config —src/editor/core/schema.ts, lightweight entry point —src/editor/schema-entry.ts. - Tests:
tests/rich-text-view.test.tsx(it also holds the module graph and the table-to-Schema check),tests/rich-text-view-footnotes.test.tsx(footnotes as plain anchors),tests/rich-text-view-code-copy.test.tsx(header, Island, copying),tests/rich-text-view-island.test.tsx(the Island of a custom Block),tests/rich-text-paper.test.tsxandtests/rich-text-paper-css.test.tsx(Paper,surface="paper"),tests/editor-highlight-entry.test.ts(highlight helper, escaping, entry point graph),tests/editor-sanitize.test.tsx(sanitizing with the real DOMPurify: the Editor's markup unchanged, forged input, the bare config),tests/editor-sanitize-tools.test.tsx(sanitizing andrichTextSchemawith custom Tools),tests/rsc-gate.test.ts. - Storybook:
Content/RichTextView. - The Editor — RichTextEditor; custom Tools, the Island and the semver boundary — Editor extension API; decisions — ADR-0050, highlighting — ADR-0051, extension — ADR-0058.
TypeScript types
RichTextViewProps
Prop
Type
Plus DOM attributes, such as onChange, onClick, className — 277 in total; the table does not repeat them.
Release 2.4
Search is twice as fast and finds words in attachments. See the migration notes.
New filters by owner and date
Saved searches
Before you upgrade: rebuild the index.
Query
Before
After
Title
120 ms
55 ms