diff --git a/package.json b/package.json index 10b3ef403..2048773ce 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@benrbray/prosemirror-math": "^0.2.2", "@bull-board/api": "^4.2.2", "@bull-board/koa": "^4.12.2", + "@css-inline/css-inline-wasm": "^0.14.0", "@dnd-kit/core": "^6.1.0", "@dnd-kit/modifiers": "^6.0.1", "@dnd-kit/sortable": "^7.0.2", @@ -98,7 +99,6 @@ "copy-to-clipboard": "^3.3.3", "core-js": "^3.36.0", "crypto-js": "^4.2.0", - "css-inline": "^0.11.2", "datadog-metrics": "^0.11.1", "date-fns": "^2.30.0", "dd-trace": "^3.51.0", diff --git a/server/emails/templates/CommentCreatedEmail.tsx b/server/emails/templates/CommentCreatedEmail.tsx index 2212369ab..c8f432ef1 100644 --- a/server/emails/templates/CommentCreatedEmail.tsx +++ b/server/emails/templates/CommentCreatedEmail.tsx @@ -82,7 +82,7 @@ export default class CommentCreatedEmail extends BaseEmail< if (content) { // inline all css so that it works in as many email providers as possible. - body = HTMLHelper.inlineCSS(content); + body = await HTMLHelper.inlineCSS(content); } const isReply = !!comment.parentCommentId; diff --git a/server/emails/templates/CommentMentionedEmail.tsx b/server/emails/templates/CommentMentionedEmail.tsx index e356b81db..77329c75b 100644 --- a/server/emails/templates/CommentMentionedEmail.tsx +++ b/server/emails/templates/CommentMentionedEmail.tsx @@ -74,7 +74,7 @@ export default class CommentMentionedEmail extends BaseEmail< if (content) { // inline all css so that it works in as many email providers as possible. - body = HTMLHelper.inlineCSS(content); + body = await HTMLHelper.inlineCSS(content); } return { diff --git a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx index 9578f3b64..654897b06 100644 --- a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx +++ b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx @@ -73,7 +73,7 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< }); // inline all css so that it works in as many email providers as possible. - body = content ? HTMLHelper.inlineCSS(content) : undefined; + body = content ? await HTMLHelper.inlineCSS(content) : undefined; } } diff --git a/server/models/helpers/HTMLHelper.test.ts b/server/models/helpers/HTMLHelper.test.ts new file mode 100644 index 000000000..4126c0852 --- /dev/null +++ b/server/models/helpers/HTMLHelper.test.ts @@ -0,0 +1,29 @@ +import HTMLHelper from "./HTMLHelper"; + +describe("HTMLHelper", () => { + const document = ` + + + + +

Big Text

+ +`; + describe("inlineCSS", () => { + it("should inline CSS from style tags", async () => { + const result = await HTMLHelper.inlineCSS(document); + expect(result).toBe(` + + + +

Big Text

+ +`); + }); + it("should initialize once", async () => { + const first = await HTMLHelper.inlineCSS(document); + const second = await HTMLHelper.inlineCSS(document); + expect(first).toBe(second); + }); + }); +}); diff --git a/server/models/helpers/HTMLHelper.ts b/server/models/helpers/HTMLHelper.ts index eea426634..97dfa84f2 100644 --- a/server/models/helpers/HTMLHelper.ts +++ b/server/models/helpers/HTMLHelper.ts @@ -1,6 +1,9 @@ -import { inline } from "css-inline"; +import { initWasm, inline } from "@css-inline/css-inline-wasm"; +import fs from "fs-extra"; import env from "@server/env"; +let initialized = false; + export default class HTMLHelper { /** * Move CSS styles from