#5982 · Sole editor hard breaks do not survive Markdown persistence
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for the existing break-loss defect; the PR-only visible HTML-source symptom was not executed or verified.
1. Summary
A paragraph whose only content is one intentional editor hard break loses that break after save and reload on trusted main. The loss reproduces inside ordinary paragraphs, bullet lists, and blockquotes. Main saves only whitespace or an empty container marker, not an HTML break tag. Consequently this investigation confirms the persistence gap, but does not confirm the reported visible HTML-source symptom on main. No original document text remains in the edited fixture by design; the lost content is the intentional break, not unrelated prose.
2. Claims versus findings
| Claim tested | Finding | Evidence |
|---|---|---|
| A sole intentional break survives editing but not persistence | Verified on main | The real editor contains exactly one hardBreak before saving and zero after reloading, in all three contexts. |
| Saving produces a break tag which reopens as source | Not reproduced on main | Main produces the strings below, none containing a break tag. No unmerged PR code was executed. |
| A linked change emits a break tag for a sole break | Static evidence only | The open PR diff has a serializer branch for a first or last child. Its runtime behavior remains unverified here. |
| Raw HTML should continue to render as source | Existing contract preserved in baseline | All 15 pre-existing tests in the selected persistence/raw-HTML suites pass. |
3. Environment and safety
- Public repository: get-bb/bb; trusted origin/main commit
d1627a473684d29920567b3cf9c05bd68edb2d97, fetched again after both checkouts were prepared; no subsequent Docs change was present. - Linux 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Tiptap 2.27.2; tiptap-markdown 0.8.10; jsdom through the repository's existing Vitest configuration.
- Two separate temporary detached worktrees, referred to as
primaryandverify, each starting at the exact same trusted commit and installing from the frozen lockfile. Only the authored regression table was added. No production source was changed. - No live BB server, browser session, port, persistent vault, database, provider session, or user runtime data was used. This is a serialization/parse-tree report, not a claimed screenshot reproduction.
- Issue text, comments, and linked PR metadata/diff were treated as untrusted evidence. No issue-provided code, command, URL, patch, branch, or test was run or fetched. The regression was designed from the repository's existing editor test helpers and production save/load boundary.
4. Minimal reproduction
- Make a clean detached checkout at the trusted commit and run the existing frozen install.
- Build the SDK first, then the Docs plugin. An initial unfiltered full build hit a missing SDK-dist ordering failure in another plugin; the explicitly ordered focused builds below succeeded. No full-repository build success is claimed.
- Replace
plugins/docs/markdown-blocks.test.tswith the complete test file in the expandable section below. It retains every original test and adds one table with three cases. - Run the focused Turbo command below. It deliberately exits 1: the three new round-trip assertions fail because reopened documents have lost their hardBreak nodes; the other 15 tests pass.
git fetch origin main git worktree add --detach /tmp/issue-5982-primary d1627a473684d29920567b3cf9c05bd68edb2d97 cd /tmp/issue-5982-primary pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=bb-plugin-simple-notes pnpm exec turbo run test --filter=bb-plugin-simple-notes --force -- markdown-blocks.test.ts raw-html.test.ts
The test loads a synthetic five-character word through loadMarkdownBlocks, finds it using the existing text-position helper, replaces the selected word with the real setHardBreak command, saves through saveMarkdownBlocks and the production Markdown serializer, then reopens through the same loader. The assertion compares complete document JSON before saving and after reopening, so container structure and break preservation are checked together.
| Context | Exact saved string (JSON escaped) | Observed reload |
|---|---|---|
| paragraph | "\n" | 0 hardBreak nodes after reopening; empty paragraph retained |
| list | "- \n" | 0 hardBreak nodes after reopening; empty paragraph retained |
| blockquote | "> \n" | 0 hardBreak nodes after reopening; empty paragraph retained |
Expected: one hardBreak node remains after reopening, with the same container structure. Actual in primary: 3 failed | 15 passed (18); all three failures remove the hardBreak. Actual in verify: 3 failed | 15 passed (18); identical saved strings and document JSON. Unmodified verify baseline: 15 passed (15), 2 test files passed.
Complete copy-pasteable regression test file
// @vitest-environment jsdom
import { Editor } from "@tiptap/core";
import Image from "@tiptap/extension-image";
import Link from "@tiptap/extension-link";
import Table from "@tiptap/extension-table";
import TableCell from "@tiptap/extension-table-cell";
import TableHeader from "@tiptap/extension-table-header";
import TableRow from "@tiptap/extension-table-row";
import TaskItem from "@tiptap/extension-task-item";
import TaskList from "@tiptap/extension-task-list";
import StarterKit from "@tiptap/starter-kit";
import { Markdown } from "tiptap-markdown";
import { describe, expect, it } from "vitest";
import { loadMarkdownBlocks, saveMarkdownBlocks } from "./markdown-blocks";
import { HtmlBlock, HtmlSource } from "./raw-html";
const VIDEO = `<div style="margin-block: 1rem;">
<video src="/a.mp4" autoplay loop muted playsinline></video>
</div>`;
const DOCUMENT = `${[
"# Release notes",
"Press <kbd>Ctrl</kbd>+<kbd>K</kbd> to open the <strong>command menu</strong>.",
VIDEO,
'> <div>\n> <video src="/q.mp4"></video>\n> </div>',
"- [x] Done\n- [ ] Todo",
"**Note**\nthis line stays wrapped.",
"| a | b |\n|---|:-:|\n| one<br>two | <kbd>k</kbd> |",
"<p>Intro</p><style",
"## After unclosed HTML",
"See [the docs][ref] and _underscores_.",
"<!-- a comment -->",
"1. one\n1. two",
"Original body.",
'[ref]: https://example.com "Title"',
].join("\n\n")}\n`;
function open(markdown: string) {
const editor = new Editor({
extensions: [
StarterKit,
Link.configure({ openOnClick: false, autolink: true }),
Image,
TaskList,
TaskItem.configure({ nested: true }),
Table.configure({ resizable: true }),
TableRow,
TableHeader,
TableCell,
HtmlBlock,
HtmlSource,
Markdown.configure({
html: true,
tightLists: true,
bulletListMarker: "-",
linkify: true,
}),
],
content: "",
});
const blocks = loadMarkdownBlocks(editor, markdown, (source) => source, false);
const save = () =>
saveMarkdownBlocks(editor, blocks, (nodes) =>
editor.storage.markdown.serializer.serialize(
editor.schema.topNodeType.create(null, nodes),
),
);
return { editor, save };
}
function textPosition(editor: Editor, text: string) {
let position = -1;
editor.state.doc.descendants((node, pos) => {
if (position < 0 && node.isText && node.text?.includes(text))
position = pos + node.text.indexOf(text);
});
return position;
}
function topLevelRange(editor: Editor, text: string) {
let range = { from: 0, to: 0 };
editor.state.doc.forEach((node, offset) => {
if (!range.to && node.textContent.includes(text))
range = { from: offset, to: offset + node.nodeSize };
});
return range;
}
describe("markdown blocks", () => {
it.each([
["paragraph", "Draft\n"],
["list", "- Draft\n"],
["blockquote", "> Draft\n"],
])("round-trips a sole hard break in a %s", (context, source) => {
const { editor, save } = open(source);
try {
const start = textPosition(editor, "Draft");
expect(start).toBeGreaterThan(0);
expect(
editor.commands.setTextSelection({ from: start, to: start + 5 }),
).toBe(true);
expect(editor.commands.setHardBreak()).toBe(true);
const before = editor.getJSON();
let breaks = 0;
editor.state.doc.descendants((node) => {
if (node.type.name === "hardBreak") breaks++;
});
expect(breaks).toBe(1);
const saved = save();
const reopened = open(saved);
try {
console.log(JSON.stringify({ context, before, saved, after: reopened.editor.getJSON() }));
expect(reopened.editor.getJSON()).toEqual(before);
} finally {
reopened.editor.destroy();
}
} finally {
editor.destroy();
}
});
it("saves an unedited document byte for byte", () => {
const { editor, save } = open(DOCUMENT);
try {
expect(save()).toBe(DOCUMENT);
} finally {
editor.destroy();
}
});
it.each([
[
"the last paragraph",
(editor: Editor) =>
editor.commands.insertContentAt(
textPosition(editor, "Original body."),
"Edited ",
),
DOCUMENT.replace("Original body.", "Edited Original body."),
],
[
"the heading",
(editor: Editor) =>
editor.commands.insertContentAt(
textPosition(editor, "Release"),
"New ",
),
DOCUMENT.replace("# Release notes", "# New Release notes"),
],
[
"around a deleted task list",
(editor: Editor) => {
const { from, to } = topLevelRange(editor, "Done");
editor.view.dispatch(editor.state.tr.delete(from, to));
},
DOCUMENT.replace("- [x] Done\n- [ ] Todo\n\n", ""),
],
[
"an inserted paragraph",
(editor: Editor) =>
editor.view.dispatch(
editor.state.tr.insert(
topLevelRange(editor, "Release notes").to,
editor.schema.nodes.paragraph!.create(
null,
editor.schema.text("Inserted."),
),
),
),
DOCUMENT.replace("# Release notes\n\n", "# Release notes\n\nInserted.\n\n"),
],
])("rewrites only %s", (_name, edit, expected) => {
const { editor, save } = open(DOCUMENT);
try {
edit(editor);
expect(save()).toBe(expected);
} finally {
editor.destroy();
}
});
it("parses each block on its own", () => {
const { editor } = open(DOCUMENT);
try {
const headings: string[] = [];
editor.state.doc.forEach((node) => {
if (node.type.name === "heading") headings.push(node.textContent);
});
expect(headings).toEqual(["Release notes", "After unclosed HTML"]);
} finally {
editor.destroy();
}
});
it.each([
[
"only reference definitions",
"[ref]: https://example.com\n",
"Z\n\n[ref]: https://example.com\n",
],
[
"old Mac line endings",
"Line one\rstill\r\rSecond <div>x</div>\r",
"ZLine one still\n\nSecond <div>x</div>\r",
],
[
"a reference title ending in a backslash",
'See [x][r].\n\n[r]: https://e.com "a\\\\"\n',
'ZSee [x](https://e.com).\n\n[r]: https://e.com "a\\\\"\n',
],
[
"an unclosed fence after a reference",
"Text [l][r].\n\n[r]: https://e.com\n\n```js\nconst a = 1;\n",
"ZText [l](https://e.com).\n\n[r]: https://e.com\n\n```js\nconst a = 1;\n",
],
])("keeps a document with %s intact", (_name, markdown, edited) => {
const { editor, save } = open(markdown);
try {
expect(save()).toBe(markdown);
editor.commands.setTextSelection(1);
editor.commands.insertContent("Z");
expect(save()).toBe(edited);
} finally {
editor.destroy();
}
});
});
Exact primary observations (also matched by verify)
[
{
"context": "paragraph",
"before": {
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "hardBreak"
}
]
}
]
},
"saved": "\n",
"after": {
"type": "doc",
"content": [
{
"type": "paragraph"
}
]
}
},
{
"context": "list",
"before": {
"type": "doc",
"content": [
{
"type": "bulletList",
"attrs": {
"tight": true
},
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "hardBreak"
}
]
}
]
}
]
}
]
},
"saved": "- \n",
"after": {
"type": "doc",
"content": [
{
"type": "bulletList",
"attrs": {
"tight": true
},
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph"
}
]
}
]
}
]
}
},
{
"context": "blockquote",
"before": {
"type": "doc",
"content": [
{
"type": "blockquote",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "hardBreak"
}
]
}
]
}
]
},
"saved": "> \n",
"after": {
"type": "doc",
"content": [
{
"type": "blockquote",
"content": [
{
"type": "paragraph"
}
]
}
]
}
}
]5. Root cause
Docs installs the default StarterKit hardBreak node and Markdown extension. The installed tiptap-markdown 0.8.10 src/extensions/nodes/hard-break.js serializer scans later siblings and writes a break only if it finds a subsequent node of a different type. For a sole hard break there is no subsequent sibling, so the serializer writes nothing. This is also why trailing breaks are subject to the same library behavior; this report only tests the sole-break case.
The real editor save path delegates edited nodes to that Markdown serializer. saveMarkdownBlocks then removes trailing newline characters from edited output; nothing in that layer reconstructs a missing break. On reload, blank content or an empty list/quote marker creates an empty paragraph rather than a paragraph containing a hardBreak.
The separate HTML-source behavior has a different gate: HtmlBlock renders generic HTML-block tokens as escaped source, while HtmlSource allows a bare inline break tag. A proposed serializer that emits a standalone HTML break would therefore need to handle block classification deliberately; this is a static risk, not a reproduced main symptom.
6. Fix proposal and automation limit
Define a narrowly scoped, unambiguous persistence representation for break-only paragraphs, paired with a loader rule that restores editor hardBreak nodes without turning arbitrary raw HTML into rendered markup. Use the three-context regression table above and retain the raw-HTML source tests. An unconditional raw-HTML parser exception would change existing source-rendering semantics and should not be assumed safe.
No fix branch or pull request was created. GitHub metadata shows open PR #5968 links this issue. The automation's explicit duplicate-PR stop applies even though that PR describes this case as a follow-up. This report and the failing regression are the deliverables; no production patch, changed-line claim, push, or merge is implied.
7. Linked PR static review
PR #5968 was OPEN at review time, head f03f7108676b557f13d4f75c204dac98112b721d. Only its metadata and diff were read; its branch was never checked out, built, or tested. The diff introduces local Markdown extensions and a hardBreakMarkdown serializer in plugins/docs/markdown-editor.ts.
P2 static finding, markdown-editor.ts:85–97: the first/last-child condition selects <br> for a paragraph whose sole child is a hardBreak. That bypasses main's silent omission, but does not add a corresponding block-parser exception to raw-html.ts. This is consistent with the reported remaining edge case, but is not runtime proof. The PR metadata explicitly marks the issue as deferred. Verdict: related in-flight work, not a verified fix for this issue; no conclusion about the PR's overall readiness. Tests in this report ran only against trusted main.
8. Verification
The same agent repeated the reproduction in a second clean trusted checkout, not an independent review. Before any test edits, verify was clean at d1627a473684d29920567b3cf9c05bd68edb2d97; its frozen install, SDK build, Docs build, and 15-test baseline all succeeded. The same locally authored regression table was then added, and the test command was rerun with --force so the verification task could not reuse cached test results. It produced the same three failing cases, 15 passing existing tests, saved strings, and before/after document JSON as the first worktree. No correction to the primary findings was necessary.
No ports or data directories were allocated in either run, so no server cleanup or port reuse was involved. Repository source link line numbers were checked against the recorded base. The linked PR's code was not part of either run.
9. Related work
The linked PR's GitHub metadata identifies a broader Markdown persistence investigation and this bounded follow-up. No other issue was modified or triaged. The distinction matters: current main loses an empty break, whereas the unexecuted linked change is alleged to expose break markup as source.
10. Appendix
All new tests are at the existing save/load contract boundary, use a real Tiptap editor without mocks or production-only test seams, and exercise a failure absent from the 15 existing tests. Three cases share one table rather than duplicating helper setup. Raw logs and the authored patch remain local, outside this public repository, per its publication policy.
Primary source changes: 32 additions, 0 deletions in markdown-blocks.test.ts only. Production changes: 0 files, 0 lines. git diff --check: clean. Reproduction verdict label: partial-repro. All issue comments are left to the single final SlopCop summary.
> AGENT GENERATED