Plate
PlateEditorsCreateTemplates
GitHub16kGitHub
DiscordDiscord
  • Feature Kits
  • Upload Files
  • Plugin
    • Plugin Methods
    • Plugin Shortcuts
    • Plugin Context
    • Plugin Components
    • Plugin Rules
    • Editing Behavior
    • Plugin Input Rules
  • Editor
    • Editor Methods
    • Controlled Value
  • Authored Changes
  • Performance
  • Static Rendering
  • HTML
  • Markdown
  • Form
  • Right-to-left
  • TypeScript
  • Debugging
  • Unit Testing
  • Browser
  • Troubleshooting
  • Locations
  • Transactions
  • Serializing
  • Roots
  • Document Meta
  • Clipboard and Paste
  • Decorations and annotations
  • Schema
  • History
  • PaginationExperimental
  • Annotations
  • DOM Coverage
  • External Text Views
  • Virtualized Rendering

Roots

PreviousNext

Use extra roots for headers, footers, synced blocks, captions, and other editable regions.

Plate stores the primary document as a normal block array. Extra roots let one editor own headers, footers, synced blocks, captions, side panels, and other editable regions without creating separate editor instances. Use roots when the content should share editor state, history, collaboration, schema, and commands.

Value shape

The shortest editor value is still an array of blocks. Plate treats it as the primary document.

const editor = createEditor({
  initialValue: [{ type: "paragraph", children: [{ text: "Body" }] }],
});


SerializingDocument Meta

On This Page

Value shapeReading and writing rootsRendering rootsContent rootsSet roots
Build your editor
Production-ready AI template and reusable components.
Get all-access
const
editor
=
createEditor
({
initialValue: [{ type: "paragraph", children: [{ text: "Body" }] }],
});

Pass initialValue.children plus initialValue.roots when the editor owns extra roots.

const editor = createEditor({
  initialValue: {
    children: [{ type: "paragraph", children: [{ text: "Body" }] }],
    roots: {
      header: [{ type: "paragraph", children: [{ text: "Draft" }] }],
      footer: [{ type: "paragraph", children: [{ text: "Internal" }] }],
    },
  },
});
const editor = createEditor({
  initialValue: {
    children: [{ type: "paragraph", children: [{ text: "Body" }] }],
    roots: {
      header: [{ type: "paragraph", children: [{ text: "Draft" }] }],
      footer: [{ type: "paragraph", children: [{ text: "Internal" }] }],
    },
  },
});

Each root is a normal Plate block array. Rootless transforms, points, and selections resolve against the current editor or view root. A root-bound view resolves rootless locations against its own root.

A live node or node key reaches its own root from any editor or view. Plugin commands follow their target the same way. Given a node from the header, a command edits the header. Called with no target, it edits the root that holds the caret. Code outside a plugin command that writes by a bare path on the editor writes the primary document, so pass a node or use useRootEditor(root) there.

Persist roots through the full Document Meta value instead of saving only one mounted root. When an application publishes a complete external snapshot, use only tx.value.replace({ children, roots, meta, selection }). It fits the combined document atomically, removes omitted roots, resets omitted persisted meta, and clears selection when selection is omitted. An invalid combined payload returns false and publishes nothing. Use tx.roots.* only for a targeted named-root change.

Reading and writing roots

Read the primary document with editor.read.children(). Read an extra root by key.

const body = editor.read.children();
const header = editor.read.root("header");
const body = editor.read.children();
const header = editor.read.root("header");

Create, replace, or delete extra roots inside editor.update.

editor.update((tx) => {
  tx.roots.create("aside:1", [
    { type: "paragraph", children: [{ text: "Aside" }] },
  ]);
});
editor.update((tx) => {
  tx.roots.create("aside:1", [
    { type: "paragraph", children: [{ text: "Aside" }] },
  ]);
});

Mutate the primary document with normal node and text transforms instead of tx.roots.

Rendering roots

Pass root to EditorContent when one React tree renders a named root.

<EditorRoot editor={editor}>
  <EditorContent aria-label="Header" root="header" />
  <EditorContent aria-label="Body" />
  <EditorContent aria-label="Footer" root="footer" />
</EditorRoot>
<EditorRoot editor={editor}>
  <EditorContent aria-label="Header" root="header" />
  <EditorContent aria-label="Body" />
  <EditorContent aria-label="Footer" root="footer" />
</EditorRoot>

Use useRootChrome(root) on non-editable wrappers that should participate in mouse selection and focus restoration for that root.

const chrome = useRootChrome("header");
 
return (
  <section {...chrome.props}>
    <EditorContent root="header" />
  </section>
);
const chrome = useRootChrome("header");
 
return (
  <section {...chrome.props}>
    <EditorContent root="header" />
  </section>
);

Use useRootState(root, selector) for UI that reads one root without subscribing to every editor change. Use useRootEditor(root) for commands that must run against a specific root. While an EditorContent shows that root, its editor.api.dom calls run in the same view of the root as its commands. Views lists the calls that run elsewhere and how the editor createEditor returns picks a view.

Content roots

Content roots attach a separately addressed editable root to an element in another root. element.childRoots[slot] stores the root key, and the detached content lives in editor.read.root(rootKey). Keep ordinary structural content in the element's children.

import { definePlugin, schema } from 'platejs/react';
 
const SyncedBlockPlugin = definePlugin('syncedBlock', {
  schema: {
    element: {
      content: schema.content.text({ default: 'text', min: 1 }),
      contentRoots: {
        body: {
          content: schema.content.type('paragraph', {
            default: { type: 'paragraph' },
            min: 1,
          }),
          ownership: 'shared',
        },
      },
    },
  },
});
import { definePlugin, schema } from 'platejs/react';
 
const SyncedBlockPlugin = definePlugin('syncedBlock', {
  schema: {
    element: {
      content: schema.content.text({ default: 'text', min: 1 }),
      contentRoots: {
        body: {
          content: schema.content.type('paragraph', {
            default: { type: 'paragraph' },
            min: 1,
          }),
          ownership: 'shared',
        },
      },
    },
  },
});

Install SyncedBlockPlugin in the editor's plugins array.

Create a persistent content root by storing the root key on the owning element and creating the named root in the same transaction.

const bodyRoot = `synced-block:${blockId}:body`;
 
editor.update((tx) => {
  tx.roots.create(bodyRoot, [
    { type: "paragraph", children: [{ text: "Synced body" }] },
  ]);
  tx.nodes.insert({
    type: "syncedBlock",
    childRoots: { body: bodyRoot },
    children: [{ text: "" }],
  });
});
const bodyRoot = `synced-block:${blockId}:body`;
 
editor.update((tx) => {
  tx.roots.create(bodyRoot, [
    { type: "paragraph", children: [{ text: "Synced body" }] },
  ]);
  tx.nodes.insert({
    type: "syncedBlock",
    childRoots: { body: bodyRoot },
    children: [{ text: "" }],
  });
});

Each contentRoots entry declares a slot, child-root grammar, and ownership. childRoots[slot] is the persisted ownership link that survives save/load and collaboration.

Use ownership: "shared" when several owners intentionally project the same root, as with synced blocks. Shared aliases stay attached to one root; removing even the last owner preserves that root. A schema with unknown: "reject" cannot hold a root that no element owns, so there the root goes with its last owner. Use ownership: "exclusive" for a separately mounted document that belongs to exactly one element, such as an element-owned annotation surface. Moving an owner preserves its root key. Removing, retargeting, or changing the type of an exclusive owner removes the root only when it becomes orphaned. In an authored propose view, deleting an owner keeps its root until someone accepts the deletion.

Set roots

Declare structure: { kind: 'set' } on an exclusive content root when each of its top-level blocks is a separate item, such as the shapes of a board. Each top-level block of the root is then a member of the set.

import { definePlugin, schema } from 'platejs/react';
 
const NotePlugin = definePlugin('note', {
  schema: {
    element: {
      content: schema.content.types(['paragraph'], {
        default: { type: 'paragraph' },
        min: 1,
      }),
      object: true,
    },
  },
});
 
const CanvasPlugin = definePlugin('canvas', {
  schema: {
    element: {
      contentRoots: {
        shapes: {
          content: schema.content.types(['note'], { min: 0 }),
          ownership: 'exclusive',
          structure: { kind: 'set' },
        },
      },
      void: 'block',
    },
  },
});
import { definePlugin, schema } from 'platejs/react';
 
const NotePlugin = definePlugin('note', {
  schema: {
    element: {
      content: schema.content.types(['paragraph'], {
        default: { type: 'paragraph' },
        min: 1,
      }),
      object: true,
    },
  },
});
 
const CanvasPlugin = definePlugin('canvas', {
  schema: {
    element: {
      contentRoots: {
        shapes: {
          content: schema.content.types(['note'







The schema refuses a set root unless its ownership is 'exclusive', its owner is a void element, and each block type the root admits is an object or a void element. Every reader then treats the members as separate items:

  • A text selection stays in one member. A selection write that crosses members, such as Select All, settles in one member and raises no error.
  • Removing text or a fragment over a range across members refuses and changes nothing. A delete over all of one member's text keeps the member, emptied.
  • Comparison reports a changed member as one change. Members keep their stored order.

A plugin can refuse a type change, wrap, or unwrap of its own owner before the write applies. Contribute a nodeWriteVeto that returns true for the writes it refuses:

import { definePlugin, nodeWriteVeto } from 'platejs';
 
const SyncedBlockGuardPlugin = definePlugin('syncedBlockGuard', {
  contributions: [
    nodeWriteVeto.of(({ node }) => node.type === 'syncedBlock'),
  ],
});
import { definePlugin, nodeWriteVeto } from 'platejs';
 
const SyncedBlockGuardPlugin = definePlugin('syncedBlockGuard', {
  contributions: [
    nodeWriteVeto.of(({ node }) => node.type === 'syncedBlock'),
  ],
});

The veto receives { kind, node, path, root }. kind is 'retype', 'wrap', or 'unwrap', and a 'retype' input also carries the new type. tx.nodes.set, tx.blocks.set, tx.blocks.reset and tx.blocks.toggle retype. tx.nodes.wrap and a wrapping toggle wrap. tx.nodes.unwrap unwraps. tx.nodes.lift counts as an unwrap of the lifted node's parent, except when it lifts the last of several children, which leaves the parent whole. tx.nodes.merge counts as an unwrap of the node it merges into the node before, unless that node before is empty and the merge removes it instead. A merge also counts as an unwrap of each ancestor it empties and removes, such as a holder whose only child merges into a block outside it, and a delete that joins two blocks merges them the same way. One refusal from any contributed veto rolls back the whole update, as a refused update does. Remote imports and history replays never consult a veto. Removing the owner is not one of these writes, so the orphan rule above still applies to it.

Duplicate and copy/paste clone detached roots. Each copy gets a key that no earlier copy took, <root>:copy:<n>, or <root>:copy:<clientID>:<n> in an editor bound to Yjs, so two collaborators' copies never share a key. Shared aliases in the copied group continue to share one remapped root. Owner-first and root-first creation are both valid inside one transaction. ContentSlice carries the transitive detached-root payload across clipboard and insertion boundaries, including a collapsed target. Cut captures that payload before deleting the owner and root in one transaction. Undo and redo restore the owner, root content, and root-qualified selection together.

Render the child root from the plugin component with slots.contentRoot(slot).

const SyncedBlock = ({ attributes, element, slots }) => (
  <section {...attributes}>
    <header>Synced block</header>
    {slots.contentRoot("body", {
      ariaLabel: "Synced block body",
      placeholder: "Empty synced block",
    })}
  </section>
);
const SyncedBlock = ({ attributes, element, slots }) => (
  <section {...attributes}>
    <header>Synced block</header>
    {slots.contentRoot("body", {
      ariaLabel: "Synced block body",
      placeholder: "Empty synced block",
    })}
  </section>
);

A root whose blocks are selected as whole objects, such as a board's shapes, can give focus to an element of its own instead of its editable. Pass nodeSelectionFocus, a ref to that element, and give the element contentEditable={false}. That element takes focus when the editor moves focus into the root, as after an undo, on a click that selects an object in the root or on a call to editor.api.dom.focus(). It takes focus only while no range is shown into the root and the root's own selection is none or a node selection of its top-level blocks. A node selection the root kept while the caret was in another root becomes the selection again once the element holds focus, so a key the element handles acts on it. It does not come back when the element's focus handler leaves focus on another element, asks for focus elsewhere or changes the selection. A focus call made inside an update or a read focuses the editable instead. Keep the element mounted across renders. When the render that follows a focus call replaces it, focus falls to the page. An element that inherits editing runs the editable's own focus handler, which in Firefox moves focus to the editable. Unless the element is a control, such as a button, the editor reads no keys from it, so it must handle the keys it needs, such as undo and redo through the onKeyDown of useEditorHistory.

const Board = ({ attributes, children, slots }) => {
  const focusTarget = useRef<HTMLDivElement>(null);
  const history = useEditorHistory();
 
  return (
    <div {...attributes}>
      <div
        ref={focusTarget}
        tabIndex={-1}
        contentEditable={false}
        onKeyDown={history.onKeyDown}
      />
      {slots.contentRoot("shapes", { nodeSelectionFocus: focusTarget })}
      {children}
    </div>
  );
};
const Board = ({ attributes, children, slots }) => {
  const focusTarget = useRef<HTMLDivElement>(null);
  const history = useEditorHistory();
 
  return (
    <div {...attributes}>
      <div
        ref={focusTarget}
        tabIndex={-1}
        contentEditable={false}
        onKeyDown={history.onKeyDown}
      />
      {slots.contentRoot("shapes", { nodeSelectionFocus: focusTarget })}



Use content roots for synced blocks, editable cards, and element-owned editable regions. Use DOM coverage boundaries when the content is in the same root but intentionally not mounted, such as a closed accordion body or inactive tab panel.

], { min:
0
}),
ownership: 'exclusive',
structure: { kind: 'set' },
},
},
void: 'block',
},
},
});
{children}
</div>
);
};