docs/solutions/best-practices/2026-05-09-lexical-codeblock-harvest-rows-need-data-transfer-boundaries.md
Lexical's CodeBlock.test.ts is not a pure code-block model suite. Its useful
portable row is rich HTML insertion from code sources: <pre>, editor
white-space: pre line wrappers, and GitHub code tables should import as code
without source gutters.
<pre>function... ...</pre> imported through Chromium native
clipboard as plain paragraphs, not a Slate code block.onPaste interception made that browser row pass, but it bypassed
the runtime command path and failed the generated paste kernel-trace gauntlet.onPaste. That stole ownership
from the runtime clipboard strategy and removed the expected insert-data
kernel trace.Keep this harvest row at the DataTransfer insertion boundary, matching Lexical's unit test shape:
insertData handle in browser proof; and line-wrapper <div> elements;<code> as inline code through the existing row;The importer should detect code-source HTML before generic table/paragraph deserialization:
if (isCodeSourceElement(el as HTMLElement)) {
return createCodeBlockElement(collectCodeSourceText(el as HTMLElement))
}
Then the full paste-html browser file must still pass, especially the generated clipboard gauntlet that asserts the runtime command trace.
The copied invariant is "code-source HTML maps to code content," not "native browser paste always preserves code blocks." DataTransfer proof covers the same insertion boundary as Lexical's unit test without weakening Slate React's clipboard runtime contract.
Keeping native clipboard transport separate also prevents a small parser row from silently changing the event pipeline. If native rich paste needs a stronger policy later, that is a runtime/browser lane with kernel-trace proof, not an app importer shortcut.
onPaste interception to fix importer behavior unless the
runtime trace contract is updated and re-proved.paste-html.test.ts browser file.