fix: Correctly strip node comments on duplication (#11700)

* Initial plan

* fix: preserve table row background colors when duplicating documents

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

* test

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
This commit is contained in:
Copilot
2026-03-10 19:25:04 -04:00
committed by GitHub
parent 83977f85bd
commit a8b701aff3
2 changed files with 84 additions and 0 deletions
@@ -269,6 +269,11 @@ export class ProsemirrorHelper {
if (node.marks) {
node.marks = node.marks.filter((mark) => !marks.includes(mark.type));
}
if (node.attrs?.marks) {
node.attrs.marks = (node.attrs.marks as { type: string }[])?.filter(
(mark) => !marks.includes(mark.type)
);
}
if (node.content) {
node.content.forEach(removeMarksInner);
}
+79
View File
@@ -1,4 +1,6 @@
import crypto from "node:crypto";
import { Node } from "prosemirror-model";
import { ProsemirrorHelper as ServerProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
import { schema } from "@server/editor";
@@ -181,4 +183,81 @@ describe("#ProsemirrorHelper", () => {
});
});
});
describe("#removeMarks", () => {
it("preserves table cell background color when removing comment marks", () => {
const doc = Node.fromJSON(schema, {
type: "doc",
content: [
{
type: "table",
content: [
{
type: "tr",
content: [
{
type: "td",
attrs: {
colspan: 1,
rowspan: 1,
alignment: null,
colwidth: null,
marks: [
{
type: "background",
attrs: { color: "#e8f5e9" },
},
{
type: "comment",
attrs: { id: "comment-1" },
},
],
},
content: [{ type: "paragraph" }],
},
],
},
],
},
],
});
const result = ServerProsemirrorHelper.removeMarks(doc, ["comment"]);
const tdAttrsMarks = result.content?.[0]?.content?.[0]?.content?.[0]
?.attrs?.marks as Array<{ type: string }> | undefined;
expect(tdAttrsMarks?.find((m) => m.type === "background")).toBeDefined();
expect(tdAttrsMarks?.find((m) => m.type === "comment")).toBeUndefined();
});
it("removes comment marks from text nodes when duplicating", () => {
const doc = Node.fromJSON(schema, {
type: "doc",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "Hello",
marks: [
{
type: "comment",
attrs: { id: "comment-2", userId: crypto.randomUUID() },
},
],
},
],
},
],
});
const result = ServerProsemirrorHelper.removeMarks(doc, ["comment"]);
const textMarks = result.content?.[0]?.content?.[0]?.marks as
| Array<{ type: string }>
| undefined;
expect(textMarks?.find((m) => m.type === "comment")).toBeUndefined();
});
});
});