Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(workflows): drop undefined keys so autosave stops reloading the email canvas (#105081)

Daniel Marchuk167d4034ce9f
diff --git a/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.test.ts b/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.test.ts
index bb5d615b3d4d..1b1e7e8979a6 100644
--- a/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.test.ts
+++ b/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.test.ts
@@ -484,16 +484,22 @@ describe('emailTemplaterLogic', () => {
expect(loadDesign).toHaveBeenLastCalledWith(DESIGN_EXTERNAL)
})
- it('does not reload the canvas when our own edit echoes back through the parent', async () => {
+ it.each([
+ ['as exported', DESIGN_EDITED],
+ [
+ 'after a save drops undefined keys',
+ { body: { ...DESIGN_EDITED.body, values: { fontFamily: undefined } } },
+ ],
+ ])('does not reload the canvas when our own edit echoes back through the parent %s', async (_, exported) => {
jest.useFakeTimers()
- editorDesign = DESIGN_EDITED
+ editorDesign = exported
editorListeners['design:updated']()
await jest.advanceTimersByTimeAsync(500)
jest.useRealTimers()
await expectLogic(logic).toFinishAllListeners()
expect(onChange).toHaveBeenCalledTimes(1)
- updateProps({ design: DESIGN_EDITED })
+ updateProps({ design: JSON.parse(JSON.stringify(exported)) })
await expectLogic(logic).toFinishAllListeners()
expect(loadDesign).toHaveBeenCalledTimes(1)
diff --git a/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.tsx b/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.tsx
index ea337d437788..dd627454e28e 100644
--- a/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.tsx
+++ b/frontend/src/scenes/hog-functions/email-templater/emailTemplaterLogic.tsx
@@ -103,6 +103,19 @@ export interface EditorRef extends _EditorRef {}
type JSONTemplate = Parameters<Editor['loadDesign']>[0]
+function exportEditorHtml(editor: Editor): Promise<{ html: string; design: JSONTemplate }> {
+ return new Promise((resolve) =>
+ editor.exportHtml((data: { html: string; design: JSONTemplate }) => {
+ let design = data.design
+ try {
+ // A save drops the undefined keys Unlayer exports, so an unnormalized export never equals it.
+ design = JSON.parse(JSON.stringify(design))
+ } catch {}
+ resolve({ ...data, design })
+ })
+ )
+}
+
/**
* Wrap raw html in an Unlayer design holding a single custom HTML block. Emails authored
* programmatically (API/MCP) often have html but no design; loading a wrapped design shows the
@@ -554,7 +567,7 @@ export const emailTemplaterLogic = kea<emailTemplaterLogicType>([
const [htmlData, textData]: [{ html: string; design: JSONTemplate }, { text: string }] =
await Promise.all([
- new Promise<any>((res) => editor.exportHtml(res)),
+ exportEditorHtml(editor),
new Promise<any>((res) => editor.exportPlainText(res)),
])
@@ -612,7 +625,7 @@ export const emailTemplaterLogic = kea<emailTemplaterLogicType>([
if (!editor) {
return
}
- const htmlData: { design: JSONTemplate } = await new Promise<any>((res) => editor.exportHtml(res))
+ const htmlData: { design: JSONTemplate } = await exportEditorHtml(editor)
breakpoint()
cache.lastEditorDesign = htmlData.design
},
@@ -633,7 +646,7 @@ export const emailTemplaterLogic = kea<emailTemplaterLogicType>([
}
const [htmlData, textData]: [{ html: string; design: JSONTemplate }, { text: string }] = await Promise.all([
- new Promise<any>((res) => editor.exportHtml(res)),
+ exportEditorHtml(editor),
new Promise<any>((res) => editor.exportPlainText(res)),
])
breakpoint()
@@ -733,7 +746,7 @@ export const emailTemplaterLogic = kea<emailTemplaterLogicType>([
if (editor) {
const [htmlData, textData]: [{ html: string; design: JSONTemplate }, { text: string }] =
await Promise.all([
- new Promise<any>((res) => editor.exportHtml(res)),
+ exportEditorHtml(editor),
new Promise<any>((res) => editor.exportPlainText(res)),
])
cache.pendingDesignEdit = false
@@ -774,7 +787,7 @@ export const emailTemplaterLogic = kea<emailTemplaterLogicType>([
const [htmlData, textData]: [{ html: string; design: JSONTemplate }, { text: string }] =
await Promise.all([
- new Promise<any>((res) => editor.exportHtml(res)),
+ exportEditorHtml(editor),
new Promise<any>((res) => editor.exportPlainText(res)),
])