docs/solutions/logic-errors/2026-05-04-clipboard-fragment-format-keys-must-guard-html-fallback.md
Custom Slate clipboard format keys are not enough if the HTML fallback still
uses an unkeyed data-slate-fragment. The browser clipboard can lose the custom
MIME payload and still carry text/html, so schema isolation has to apply to
both channels.
application/${clipboardFormatKey} was configurable.text/html still carried a bare data-slate-fragment.dom.clipboard.insertData handlers
without reaching into private runtime files or using unknown.text/html.slate-dom.Write a format marker beside every embedded fragment and require it to match the receiving editor's configured key:
attachElement.setAttribute('data-slate-fragment', encoded)
attachElement.setAttribute('data-slate-fragment-format', clipboardFormatKey)
data.setData(`application/${clipboardFormatKey}`, encoded)
Import then checks both channels against the same key:
const fragment =
data.getData(`application/${clipboardFormatKey}`) ||
getSlateFragmentAttribute(data, clipboardFormatKey)
Keep default compatibility narrow:
clipboardFormatKey;x-slate-fragment;Expose extension-owned paste handling through a public type:
export type DOMClipboardInsertDataHandler<V extends Value = Value> = (
editor: DOMEditor<V>,
data: DataTransfer
) => boolean | void
Examples can then register rich HTML/image paste behavior without private runtime imports:
const insertData: DOMClipboardInsertDataHandler = (_editor, data) =>
insertHtmlData(editor, data)
editor.extend({
capabilities: {
'dom.clipboard.insertData': insertData,
},
name: 'paste-html',
})
The internal Slate fragment is trusted only when the transport identity matches the receiving editor. The fallback path remains useful for normal browser copy flows, but it no longer bypasses schema isolation when the custom MIME payload is absent.
The public handler type keeps extension-owned rich paste policy in the
capability layer. slate-dom owns transport and trust boundaries; apps own
foreign HTML interpretation.
application/* and text/html
fallback paths.docs/solutions/logic-errors/2026-04-03-slate-v2-clipboard-boundary-proof-must-split-fragment-semantics-and-dom-transport.mddocs/solutions/logic-errors/2026-05-04-inline-void-clipboard-export-must-not-assume-block-void-spacer-dom.mddocs/solutions/developer-experience/2026-05-03-slate-public-root-hard-cuts-need-internal-imports-and-explicit-type-exports.md