From e0a455e3be751790ac0106ab65e5b694aedba0ab Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 27 Nov 2026 08:49:19 -0500 Subject: [PATCH] fix: Align static share rendering with document presenter (#14777) --- server/models/helpers/DocumentHelper.test.ts | 33 ++++++++++++++++++++ server/models/helpers/DocumentHelper.tsx | 11 +++++-- server/utils/RedisPrefixHelper.ts | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/server/models/helpers/DocumentHelper.test.ts b/server/models/helpers/DocumentHelper.test.ts index 87cf1eddb4..4e254bcd79 100644 --- a/server/models/helpers/DocumentHelper.test.ts +++ b/server/models/helpers/DocumentHelper.test.ts @@ -177,6 +177,39 @@ describe("DocumentHelper", () => { }); }); + describe("toStaticHTML", () => { + it("should remove comment marks", async () => { + const document = await buildDocument({ + text: "hello", + content: { + type: "doc", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + text: "hello", + marks: [ + { + type: "comment", + attrs: { id: "comment-123", userId: "user-123" }, + }, + ], + }, + ], + }, + ], + }, + }); + + const html = await DocumentHelper.toStaticHTML(document); + expect(html).toContain("hello"); + expect(html).not.toContain("comment-123"); + expect(html).not.toContain("user-123"); + }); + }); + describe("toHTML", () => { it("should return html", async () => { const document = await buildDocument({ diff --git a/server/models/helpers/DocumentHelper.tsx b/server/models/helpers/DocumentHelper.tsx index 316f942362..98a8fb2ddf 100644 --- a/server/models/helpers/DocumentHelper.tsx +++ b/server/models/helpers/DocumentHelper.tsx @@ -478,13 +478,20 @@ export class DocumentHelper { /** * Returns the document or collection as static HTML with its title. The - * output is rendered from the schema without node components or styles. + * output is rendered from the schema without node components or styles, and + * comment marks are removed because it is shown on public shares. * * @param model The document or collection to convert. * @returns The title and content as a HTML string. */ static async toStaticHTML(model: Document | Collection) { - return ProsemirrorHelper.toStaticHTML(DocumentHelper.toProsemirror(model), { + const node = Node.fromJSON( + schema, + ProsemirrorHelper.removeMarks(DocumentHelper.toProsemirror(model), [ + "comment", + ]) + ); + return ProsemirrorHelper.toStaticHTML(node, { title: model instanceof Collection ? model.name : model.title, headingPrefix: model instanceof Document diff --git a/server/utils/RedisPrefixHelper.ts b/server/utils/RedisPrefixHelper.ts index eb8444f05a..4e8450215d 100644 --- a/server/utils/RedisPrefixHelper.ts +++ b/server/utils/RedisPrefixHelper.ts @@ -45,7 +45,7 @@ export class RedisPrefixHelper { * @returns the cache key string. */ public static getShareContentKey(id: string, updatedAt: Date) { - return `share:html:${id}:${updatedAt.getTime()}`; + return `share:html:v2:${id}:${updatedAt.getTime()}`; } /**