Lazy loading the engine: Tiptap as a separate chunk
A custom Tool with Tiptap in a separate chunk: what the author sees while the chunk loads and if loading fails.
The Extensions (engine) can be handed over not as an array but as a
Loader — a function with a dynamic import. Then the module with the
Tool description is imported on the server too (Schema rules are data), and Tiptap and React go
into a separate chunk.
Try it
Press “Restart the editor” — for a second and a half the field is a Skeleton. Check “Fail the first load” and restart: a field error and a “Retry” button appear.
How it works
Readiness waits for Loaders
The engine is created once the Loaders of every Tool in tools are done: the Schema is fixed at
creation, and Blocks without their Extensions would be lost on parse. Until then the
Handle (ref) methods do nothing and onReady is not called: that's how the field behaves before
Readiness.
The Skeleton
The Skeleton is the frame, the Toolbar's place and the Document sanitized by the Schema — no input and no height jump. A Block whose Loader hasn't finished shows as text. On the server the Skeleton is only the frame.
A failed load
The field shows the error “The editor couldn't start” and a “Retry” button. The button retries only the Loaders that failed; the Document stays visible all along.
The promise is cached per Loader function
A second Editor with the same Tool doesn't have to wait again if the Loader is the same function. So the Loader is one function per module, not a new arrow function on every render. The example builds a new Loader on every restart just to show the Skeleton again.
The code block and the table in the full Preset are lazy too: their Extensions arrive as a
separate chunk. To get the chunk together with the page, add modulepreload for it — take the
URL from your bundler's manifest. How much the basic and full Presets weigh is in
“Import size”.
Server-side HTML sanitization: safe saving and display
sanitizeRichText with the same tools array on save, server-side code highlighting and RichTextView in a Next.js server component.
Your own brand and themes
An accent, the kit's brand and your own brand in one CSS block — the Editor and the Paper recolor without touching components.