diff --git a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx index b9bc6fd2b..e993dd67e 100644 --- a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx +++ b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx @@ -76,12 +76,14 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< }); // inline all css so that it works in as many email providers as possible. - body = await inlineCss(content, { - url: env.URL, - applyStyleTags: true, - applyLinkTags: false, - removeStyleTags: true, - }); + body = content + ? await inlineCss(content, { + url: env.URL, + applyStyleTags: true, + applyLinkTags: false, + removeStyleTags: true, + }) + : undefined; } } diff --git a/server/models/helpers/DocumentHelper.test.ts b/server/models/helpers/DocumentHelper.test.ts index e0092a26d..a920178c9 100644 --- a/server/models/helpers/DocumentHelper.test.ts +++ b/server/models/helpers/DocumentHelper.test.ts @@ -113,6 +113,25 @@ same on both sides`, expect(html).not.toContain("this is a highlight"); }); + it("should return undefined if no diff is renderable", async () => { + const before = new Revision({ + title: "Title", + text: ` +This is a test paragraph`, + }); + + const after = new Revision({ + title: "Title", + text: ` +This is a [test paragraph](https://example.net)`, + }); + + // Note: This test may fail in the future when support for diffing marks + // is improved. + const html = await DocumentHelper.toEmailDiff(before, after); + expect(html).toBeUndefined(); + }); + it("should trim table rows to show minimal diff including header", async () => { const before = new Revision({ title: "Title", diff --git a/server/models/helpers/DocumentHelper.tsx b/server/models/helpers/DocumentHelper.tsx index b1c501922..c4e520980 100644 --- a/server/models/helpers/DocumentHelper.tsx +++ b/server/models/helpers/DocumentHelper.tsx @@ -195,6 +195,13 @@ export default class DocumentHelper { const containsDiffElement = (node: Element | null) => node && node.innerHTML.includes("data-operation-index"); + // The diffing lib isn't able to catch all changes currently, e.g. changing + // the type of a mark will result in an empty diff. + // see: https://github.com/tnwinc/htmldiff.js/issues/10 + if (!containsDiffElement(doc.querySelector("#content"))) { + return; + } + // We use querySelectorAll to get a static NodeList as we'll be modifying // it as we iterate, rather than getting content.childNodes. const contents = doc.querySelectorAll("#content > *");