From a8b701aff3bc7b2e98abf383d5756701e292ca4e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 19:25:04 -0400 Subject: [PATCH] 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 --- server/models/helpers/ProsemirrorHelper.tsx | 5 ++ server/utils/ProsemirrorHelper.test.ts | 79 +++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/server/models/helpers/ProsemirrorHelper.tsx b/server/models/helpers/ProsemirrorHelper.tsx index 37e8576fbb..238cf55513 100644 --- a/server/models/helpers/ProsemirrorHelper.tsx +++ b/server/models/helpers/ProsemirrorHelper.tsx @@ -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); } diff --git a/server/utils/ProsemirrorHelper.test.ts b/server/utils/ProsemirrorHelper.test.ts index 02bd92e5d7..36a20bc5a2 100644 --- a/server/utils/ProsemirrorHelper.test.ts +++ b/server/utils/ProsemirrorHelper.test.ts @@ -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(); + }); + }); });