--- title: Merge description: Merge diverged document drafts with conflict resolution and apply directly without suggestions. --- This example runs a three-way merge between a captured base snapshot, a live editable document, and an incoming AI draft. Disjoint edits merge automatically, overlapping edits surface as structured conflict cards, and the resolved result lands directly in one undoable step without suggestion marks. ## Demo ## Source ## Usage - `merge({ base, current, incoming, resolutions, schema })` from `platejs/diff` merges three document snapshots by stable element identity and accepts ID-less drafts (such as AI or Markdown output). - `applyDiff({ editor, diff })` from `platejs/diff` commits the resolved `PreparedDiff` directly onto the live solo editor in one undoable step without installing `AuthoredPlugin`. - `MergeView` displays an optional drafting state while the incoming branch streams, updates a single read-only merged preview editor in place, renders conflict cards with **Keep current**, **Take incoming**, **Keep both**, and **Custom** controls, and guards against stale writes when the live document changes. - `BasicMarksKit` and `AlignKit` configure the editable document and merged preview. ## Resolve conflicts and apply directly Run stateless `merge()` with the latest `resolutions` array until `result.kind === "ready"`, then pass `result.diff` to `applyDiff()`: ```tsx import { applyDiff, merge, type MergeResolution } from "platejs/diff"; const result = await merge({ base, current: editor.read.value(), incoming: aiDraft, resolutions: selectedResolutions as readonly MergeResolution[], schema: editor.read.schema, }); if (result.kind === "ready") { await applyDiff({ diff: result.diff, editor }); } ``` If the live document changes in an unrelated paragraph while you review conflicts, deterministic conflict IDs keep your existing choices intact. If the live document changes before `applyDiff` runs, `applyDiff` returns `{ kind: "stale" }` without overwriting newer edits. See [Version History](/docs/examples/version-history) for two-way revision comparison and selective restore, or [Authored Changes](/docs/authored-changes) to review changes as tracked suggestions instead of applying them directly.