Olddevs UI4.14.0
ReferenceRichTextView

Custom Block

Custom Block

RichTextView shows a custom Block (div[data-block="acme_card"], section "Custom Tool" of the RichTextEditor page) as sanitized HTML and gives it the same vertical rhythm as a paragraph, and nothing more: the spacing to the next Block is the same as for a paragraph in the same place (in a Document, a quote, a cell, a column). Blocks inside a custom container Block get the Document's rhythm, as in a Wrapper; inline content (text, Atoms, Marks) gets no spacing. On Paper it is the same.

The look comes from the consumer's CSS, which targets the data-block selector and uses the kit's tokens; there are no style fields in the Tool description. Write styles using theme variables — then the Block is the same in the Editor, in RichTextView and on the Paper, which switches the tokens itself:

[data-block="acme_card"] {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0.75rem;
}

A node view from the Extensions (a React view) is not used in RichTextView: there is no engine here. An inline Atom is shown as whatever is in the HTML: an empty span with no text is not visible; a Block can be brought to life in the View with an Island (the next section). The rhythm is checked by tests/rich-text-paper-css.test.tsx on the real cascade.

Custom Block's Island

A custom Block can be brought to life in RichTextView with a client component (a button, a player, a Details Block); the Tool description puts it into the Block's island field. Not every Block needs an Island: without it the Block stays sanitized HTML ("Custom Block").

// acme-player.tsx — a module with the directive: the server gets only a reference to the component
"use client";
import type { CustomIslandProps } from "@olddevs/ui/editor";

export function AcmePlayer({ attributes, text }: CustomIslandProps) {
  return <audio controls src={attributes.acme_src} aria-label={text} />;
}
// acme-tool.ts — the Tool description, shared by the Editor, sanitizing and the View
import { AcmePlayer } from "./acme-player";

export const acmePlayer: CustomTool = {
  name: "acme_player",
  engine: [AcmePlayerNode],
  blocks: {
    acme_player: { kind: "block", attributes: { acme_src: { kind: "url" } }, island: AcmePlayer },
  },
};

// the page is a server component
<RichTextView html={safeHtml} tools={[acmePlayer]} />;

What the component receives (CustomIslandProps): block — the Block's name, attributes — the attributes declared in the Block's attributes that are present in the HTML, by names without data- (acme_src; the component does not see an undeclared attribute), text — the Block's textContent from the server HTML. The values are strings from the Document's sanitized HTML: sanitizeRichText(html, DOMPurify, tools) checks a value's kind on the server, and without it the Island gets whatever is in html.

How it works and why RichTextView stays a server component. It works the same way as for "Copy" (the section above): the component itself has no state, and the client piece is a separate file with its own directive.

  1. The whole Tool description (Extensions, functions) cannot cross the RSC boundary, so RichTextView picks only the Islands from tools, and only those of Blocks whose data-block="<name>" is in the Document (islandsFor, src/editor/core/viewIsland.ts), and passes references to client components and attribute names to the Island. If there is no tools, no island on the Block, or no such Block in the Document, there is no Island at all: no anchor <template> in the markup, no effect, no loading of the consumer's Island code (the server serializes a reference to a client component only when the Block is there). island must be a component from a module with "use client": a server component or a function with a dynamic import is not passed to a client Island.
  2. The Block's server HTML is always in the page. Before hydration, before the Island loads and without JS, the reader sees it — that is, the Block's content as it was saved.
  3. After mounting, the Island (src/editor/ui/BlockIsland.tsx and the implementation in BlockIslandSlots.tsx, with its own "use client") finds the Blocks of its own View the same way "Copy" finds its Mount points: going left from its anchor <template>, not through the global document — a View in a shadow root or an iframe works. In every occurrence of the Block, the content is replaced by the Island; when tools changes (the Island is gone) or the Block goes away, the content comes back. If a Block with an Island sits inside another Block with an Island, the outer one comes to life: the component gets its whole text, and the inner one stays as its content.
  4. The Island's state is not reset by a parent re-render: the Island looks for Blocks again only when the Document changed, not tools (an inline array literal in the parent does not remount the Island). For this, RichTextView keeps the dangerouslySetInnerHTML object stable (useMemo on the Document): a new object on every re-render would make React rewrite the markup together with the inserted Islands and "Copy" buttons.

The Island is a separate component, not the React view from the Extensions; the Editor does not read the island field.

Cost. The Island implementation (BlockIslandSlots.tsx) is loaded lazily (React.lazy) and is not part of the View's first load: while the chunk is in flight, the Block's server HTML is visible. The static editorView measurement includes only the shell and the choice of Islands — about 0.2 kB gzip; Tiptap is still not in the View's graph, which tests/rich-text-view.test.tsx checks.

On this page