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): keep graph branches on their side when a step is added (#129428)

Michael Reichenbach3cd902ef838b
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 83be89bfc024..61c10c2d8a7a 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8551,17 +8551,17 @@ snapshots:
products-workflows-editor-configuration-panel--webhook--light:
hash: v1.k794b7964.50f31a08c94115097306a76810343499b35294055b5f6a96d8466a77ff6dd72c.KgUwEqV9D2ROlg3pazBZGDM3-z7W6595ojBL0uvLGRc
products-workflows-editor-graph--add-on-promotion-emails--dark:
- hash: v1.k794b7964.d09d47c2e08108e179ccc2329cad258baa0d76936028631f6f83fdbb72fed6df.SUCRLKNn9Ef2NM99NcBkHn7xAU10G-Z7jRC6v8rM2Us
+ hash: v1.k794b7964.7db3a946182f054df76c6ee7f9583ecd903f0b840002bd395ef8ba5fc6843b68.5T_XKw_YTklY2LHnIY-qcqlrP4DUOMsRDtvNOQHWdjE
products-workflows-editor-graph--add-on-promotion-emails--light:
- hash: v1.k794b7964.459a11941ad814aa75cad1b59e93055d1b4e2d2492efad36811ed7376799c32c.yDEGEvDRXv70gpBYs1J4xUYOVajQiYsLUqD_POtqyc0
+ hash: v1.k794b7964.a1e759ee9fffca4fa21457f342108bfab3246a506843853e16c35d40b66fa1e4.Gcgbh5o59BXZMvrJaQw3sNwR6-w3657v_WlbSgkJ2Qc
products-workflows-editor-graph--customer-onboarding-and-retention--dark:
- hash: v1.k794b7964.8c290175ab272717691996848ddf6466bb9e5160b9f669e0665ec632e59b1673._TrlJjNnqHR2O3aFlhOTHvvguIP4kpTamCtDeOCZyGI
+ hash: v1.k794b7964.7f1240ea2e401403097ede1060b7e25f0b2df5f1d9743ef08bb6941dd692e23b.RCZdGruSNFGnbW3rT57dl1RzvF_Bgziy3BnA6fYcpFs
products-workflows-editor-graph--customer-onboarding-and-retention--light:
- hash: v1.k794b7964.48ad3619a33844194ad5be15229368ac911b778a3f0960537c8c7709cc1f33ca.g25NilPWp5_YJQSWnQ9F5xsHYVNx0Vc6srQDuDCVZ0Y
+ hash: v1.k794b7964.1d255032a76f53b3772d691492c9df5b6d2cc8f433102cf77056d2ded7f0ec52.JBR3WodHJMTjtET7451p-ii3WxT3Pa9m0GCPW0Vg0Ho
products-workflows-editor-graph--narrow-workflow--dark:
- hash: v1.k794b7964.3c999b024c3fe403f0251807b6fed46dea0d1ce33635ba9c16d854fa5154fc6c.oe97w6gOWNlLBqVXmR9cwJdbsQT5ZVjAQxgdcBGiFYw
+ hash: v1.k794b7964.5ff30ad312f22fa5efb2d69d33c8b646b37f1eaa1c20273624abea8da2695385.SzcyAFbI-V2e7lVn43pBB09H3ljKxR7h42KHbnsU_J8
products-workflows-editor-graph--narrow-workflow--light:
- hash: v1.k794b7964.03aac81ae100d88cfb99387fe789002177e4e7dbecc9d9d45ec6dcd4d62d73de.V4ht6ObddMF6m23ns1MmazNLEHKEPhZP2d7rs9Heg9g
+ hash: v1.k794b7964.4bc3ee5b43a357b995a1d0c811cfec4d25beac7cdab5f5fbde0e7440cb0d290c.pJsODEUTl7LDCmAz9PoMXm3e9uFlxyagkTxXiwX0Qio
products-workflows-editor-graph--new-workflow--dark:
hash: v1.k794b7964.f679d013a77cb96c53d5663ae2f66b0ad0230eb68ea5c98a4b579ab144ae1a70.EBukMpAzfN9dx4fJ_Vonsm3YoNL1G8ulVu0wfGt8MVA
products-workflows-editor-graph--new-workflow--light:
@@ -8575,13 +8575,13 @@ snapshots:
products-workflows-editor-graph--renewal-window-alerts--light:
hash: v1.k794b7964.19b0719a16b301cf66f73f434ab4db447c6bc0f9baca1dc4d211612c6b02c0a4.QGlrBZazFF9lt8eYqanWw4Ku6zncuc23tMq5QxftX0w
products-workflows-editor-graph--support-sla-routing--dark:
- hash: v1.k794b7964.1572d26439be4a89d722a1c02d81e73f81a4fffa435849418b9548e3a9805eaf.CqAqit6-Aqv2wb75sZQHagOAQMtRFS49IEMxHl39oXA
+ hash: v1.k794b7964.ec785571118345d28b0024f9b7dbd752c0ca29b014de70f514e29d4d1e254774.CLbb0vxCoY_MAeoxx4nZ8idnAhS94Zv3u96mGm65huM
products-workflows-editor-graph--support-sla-routing--light:
- hash: v1.k794b7964.7da9940d809322739e24142d5c513e9ea4cad9ff011779c5c26998cfaec24bb9.j7q5YusxDubsQpy3eiCFwNBRw6BeQUziOxHxIY7LaAk
+ hash: v1.k794b7964.87ebdaa62ffea5299872bf5b8595333606db612d3172c77d965c7567f9e2c5f5.H8yPhfb_9AJBqMxoFMubMcFyAmyc0rHSMfLvsz7RWQs
products-workflows-editor-graph--with-navigation--dark:
- hash: v1.k794b7964.5f370b85344e6b2c4b44988d8bc2e13e647d1ae527720dce8d05e2b15a545381.H1s-o4FdoUogWavEbPSblWOU6HyHlCvOP8V-kI_fJyA
+ hash: v1.k794b7964.dc721e65f438bf7fe2013543ff26dde41b16ce179086b5629e9b182e7e9fe483.T27e_uDxg83LB3eFtxlSWpVURFyifK7b51mVmX0SA2U
products-workflows-editor-graph--with-navigation--light:
- hash: v1.k794b7964.80893cf0e8c8e443606cad555c64cc7e33323c3d4da76599c8e63f7ca1c291bd.5ATLbGHLQWlJfeMpGAo-7Zld7eNzLRqjOkp2MwxmpV4
+ hash: v1.k794b7964.5767ba8d3b87f362fd36271e24d446f990bbf86aff2024da1e6fe269644805cc.4pktGj-uAP68UGvPlyCThR0LcIIKU6oOPBlxjWH3_ds
products-workflows-editor-tile-canvas--long-emails--dark:
hash: v1.k794b7964.1952a127037bb7742f34a262ba7383326e4f5e04c86ffd58caf988de908d8fe0.lASWXxfI4hHT-xShH9moFcK8Fsd5JbnWjflhV6hu1dI
products-workflows-editor-tile-canvas--long-emails--light:
diff --git a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.test.ts b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.test.ts
index 1e5d9ce8a1df..e49233ece589 100644
--- a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.test.ts
+++ b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.test.ts
@@ -887,4 +887,75 @@ describe('hogFlowEditorLogic', () => {
expect(branchJoinDropzones()).toEqual(expected)
})
})
+
+ describe('graph layout', () => {
+ const step = (id: string, type: HogFlowAction['type'], conditions = 0): HogFlowAction =>
+ ({
+ id,
+ type,
+ name: id,
+ description: '',
+ created_at: 1,
+ updated_at: 1,
+ config:
+ type === 'conditional_branch'
+ ? { conditions: Array.from({ length: conditions }, () => ({ filters: {} })) }
+ : type === 'delay'
+ ? { delay_duration: '1d' }
+ : {},
+ }) as HogFlowAction
+
+ const xOf = (id: string): number => {
+ const node = logic.values.nodes.find((candidate) => candidate.id === id)
+ if (!node) {
+ throw new Error(`node ${id} was not laid out`)
+ }
+ return node.position.x
+ }
+
+ beforeEach(async () => {
+ await expectLogic(logic).toDispatchActions(['setNodesRaw'])
+ })
+
+ it('keeps each branch on its own side after a step is added above a nested condition', async () => {
+ const flow: HogFlow = {
+ ...NEW_WORKFLOW,
+ actions: [
+ step('trigger', 'trigger'),
+ step('route', 'conditional_branch', 1),
+ step('added', 'delay'),
+ step('choose', 'conditional_branch', 2),
+ step('first', 'delay'),
+ step('second', 'delay'),
+ step('second_followup', 'delay'),
+ step('wait', 'conditional_branch', 1),
+ step('follow_up', 'delay'),
+ step('outcome', 'delay'),
+ step('exit', 'exit'),
+ ],
+ edges: [
+ edge('trigger', 'route', 'continue'),
+ edge('route', 'added', 'branch', 0),
+ edge('added', 'choose', 'continue'),
+ edge('choose', 'first', 'branch', 0),
+ edge('first', 'exit', 'continue'),
+ edge('choose', 'second', 'branch', 1),
+ edge('second', 'second_followup', 'continue'),
+ edge('second_followup', 'exit', 'continue'),
+ edge('choose', 'exit', 'continue'),
+ edge('route', 'wait', 'branch', 1),
+ edge('wait', 'outcome', 'branch', 0),
+ edge('wait', 'follow_up', 'continue'),
+ edge('follow_up', 'outcome', 'continue'),
+ edge('outcome', 'exit', 'continue'),
+ edge('route', 'exit', 'continue'),
+ ],
+ }
+
+ await expectLogic(logic, () => logic.actions.resetFlowFromHogFlow(flow)).toDispatchActions(['setNodesRaw'])
+
+ expect(xOf('added')).toBeLessThan(xOf('wait'))
+ expect(xOf('first')).toBeLessThan(xOf('second'))
+ })
+ })
})
diff --git a/products/workflows/frontend/Workflows/hogflows/react_flow_utils/autolayout.ts b/products/workflows/frontend/Workflows/hogflows/react_flow_utils/autolayout.ts
index 96138fc6a497..e764055d91d1 100644
--- a/products/workflows/frontend/Workflows/hogflows/react_flow_utils/autolayout.ts
+++ b/products/workflows/frontend/Workflows/hogflows/react_flow_utils/autolayout.ts
@@ -35,6 +35,9 @@ export const getFormattedNodes = async (nodes: HogFlowActionNode[], edges: Edge[
'elk.spacing.edgeEdge': `${NODE_EDGE_GAP}`,
'elk.spacing.edgeNode': `${NODE_EDGE_GAP}`,
'elk.direction': 'DOWN',
+ // Keep each branch's first step in one layer with its siblings, so the fixed port order keeps the
+ // branches left to right. The default layering can move that step down a layer and to the other side.
+ 'elk.layered.layering.strategy': 'LONGEST_PATH_SOURCE',
'elk.layered.nodePlacement.strategy': 'SIMPLE',
'elk.alignment': 'CENTER',
'elk.layered.nodePlacement.bk.fixedAlignment': 'BALANCED',