fix(email): wrap root blocks in valid MJML layouts
Quality / quality (ubuntu-latest) (push) Failing after 10m0s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 15:56:23 +05:30
1 parent 7afd60e812
commit 2a93e141aa
4 files changed
+37 -3

No files matched your search

+14 -2
View File
@@ -32,6 +32,8 @@ const html = (value: unknown) =>
.replaceAll('"', """)
.replaceAll("'", "'");
const attrs = (node: BlockNode) => node.props as Record<string, unknown>;
const isEmailRootChild = (node: BlockNode, context: unknown) =>
(context as { rootBlockIds?: string[] } | undefined)?.rootBlockIds?.includes(node.id) ?? false;
export const ampLayoutClass = (node: BlockNode) =>
"wrn-layout-" + Array.from(node.id, char => char.codePointAt(0)!.toString(16)).join("-");
@@ -228,7 +230,9 @@ export const columnsBlock = defineBlock({
),
ampEmail: ({ node, slots }) =>
emailCell(`<table role="presentation" width="100%"><tr class="wrn-columns">${slots.columns}</tr></table>`, node),
mjml: ({ slots }) => slots.columns,
mjml: ({ node, slots, context }) => isEmailRootChild(node, context)
? `<mj-section padding="0">${slots.columns}</mj-section>`
: slots.columns,
},
textRenderer: ({ slots }) => slots.columns,
} satisfies BlockDefinition);
@@ -285,7 +289,15 @@ const leaf = (
slots: {},
},
create: ({ id }) => ({ id: id(), type, version: 1, props: {}, styles: {}, slots: {} }),
renderers,
renderers: {
...renderers,
...(renderers?.mjml ? { mjml: async (input) => {
const content = await renderers.mjml!(input);
return isEmailRootChild(input.node, input.context)
? `<mj-section padding="0"><mj-column padding="0">${content}</mj-column></mj-section>`
: content;
} } : {}),
},
textRenderer,
});