Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-10351): flatten 3D context on Flippable face containers (#6241)
Aaron Perezdae4c09921b6
diff --git a/skyvern-frontend/src/components/Flippable.tsx b/skyvern-frontend/src/components/Flippable.tsxindex 8f43e63d8..846db69e7 100644--- a/skyvern-frontend/src/components/Flippable.tsx+++ b/skyvern-frontend/src/components/Flippable.tsx@@ -76,6 +76,8 @@ export function Flippable({style={{backfaceVisibility: "hidden",WebkitBackfaceVisibility: "hidden",+ transformStyle: "flat",+ WebkitTransformStyle: "flat",}}>{front}@@ -87,6 +89,8 @@ export function Flippable({backfaceVisibility: "hidden",WebkitBackfaceVisibility: "hidden",transform: "rotateY(180deg)",+ transformStyle: "flat",+ WebkitTransformStyle: "flat",}}>{back}diff --git a/skyvern-frontend/src/routes/workflows/editor/nestedConditionalSave.test.ts b/skyvern-frontend/src/routes/workflows/editor/nestedConditionalSave.test.tsnew file mode 100644index 000000000..7c9446594--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nestedConditionalSave.test.ts@@ -0,0 +1,153 @@+import { describe, expect, test } from "vitest";++import { ProxyLocation } from "@/api/types";++import type {+ CodeBlock,+ ConditionalBlock,+ OutputParameter,+ WorkflowBlock,+ WorkflowSettings,+} from "../types/workflowTypes";++import {+ getElements,+ getWorkflowBlocks,+ validateWorkflowBlocks,+} from "./workflowEditorUtils";++const DEFAULT_SETTINGS: WorkflowSettings = {+ proxyLocation: ProxyLocation.Residential,+ webhookCallbackUrl: null,+ persistBrowserSession: false,+ browserProfileId: null,+ model: null,+ maxScreenshotScrolls: null,+ extraHttpHeaders: null,+ cdpConnectHeaders: null,+ runWith: "code",+ codeVersion: 2,+ scriptCacheKey: null,+ aiFallback: true,+ runSequentially: false,+ sequentialKey: null,+ finallyBlockLabel: null,+ workflowSystemPrompt: null,+};++function op(label: string): OutputParameter {+ return {+ parameter_type: "output",+ key: `${label}_output`,+ description: null,+ output_parameter_id: `op-${label}`,+ workflow_id: "wf-fixture",+ created_at: "2026-05-28T00:00:00Z",+ modified_at: "2026-05-28T00:00:00Z",+ deleted_at: null,+ };+}++function code(label: string, next: string | null): CodeBlock {+ return {+ label,+ block_type: "code",+ continue_on_failure: false,+ model: null,+ next_block_label: next,+ output_parameter: op(label),+ code: `# ${label}`,+ parameters: [],+ };+}++function conditional(+ label: string,+ mergeNext: string | null,+ branches: Array<{ id: string; next: string | null; isDefault?: boolean }>,+): ConditionalBlock {+ return {+ label,+ block_type: "conditional",+ continue_on_failure: false,+ model: null,+ next_block_label: mergeNext,+ output_parameter: op(label),+ branch_conditions: branches.map((branch) => ({+ id: branch.id,+ description: branch.id,+ next_block_label: branch.next,+ criteria: null,+ is_default: branch.isDefault ?? false,+ })),+ };+}++/**+ * SKY-10460: a conditional nested inside another conditional, with a block+ * inside the inner conditional's branch. The inner branch's next_block_label+ * must point at that block so it stays reachable; otherwise save fails with+ * "Disconnected blocks detected".+ */+describe("nested conditional save round-trip", () => {+ test("inner conditional branch block stays reachable through load -> save", () => {+ const blocks: Array<WorkflowBlock> = [+ conditional("outer", null, [+ { id: "outer-a", next: "inner" },+ { id: "outer-b", next: "block_2", isDefault: true },+ ]),+ conditional("inner", null, [+ { id: "inner-a", next: "block_1" },+ { id: "inner-b", next: null, isDefault: true },+ ]),+ code("block_1", null),+ code("block_2", null),+ ];++ const { nodes, edges } = getElements(blocks, DEFAULT_SETTINGS, true);+ const saved = getWorkflowBlocks(nodes, edges);++ const innerSaved = saved.find((block) => block.label === "inner");+ expect(innerSaved?.block_type).toBe("conditional");+ const innerBranchA = (+ innerSaved as ConditionalBlock+ ).branch_conditions.find((branch) => branch.id === "inner-a");+ expect(innerBranchA?.next_block_label).toBe("block_1");++ expect(() =>+ validateWorkflowBlocks(saved as Array<WorkflowBlock>),+ ).not.toThrow();+ });++ test("reload is robust to the inner block preceding the inner conditional in the array", () => {+ // getWorkflowBlocks appends conditional-branch children in node order, so+ // the persisted array can list block_1 before its owning inner conditional.+ // reconstructConditionalStructure must still attribute block_1 to the inner+ // conditional and produce a connected save.+ const blocks: Array<WorkflowBlock> = [+ conditional("outer", null, [+ { id: "outer-a", next: "inner" },+ { id: "outer-b", next: "block_2", isDefault: true },+ ]),+ code("block_1", null),+ conditional("inner", null, [+ { id: "inner-a", next: "block_1" },+ { id: "inner-b", next: null, isDefault: true },+ ]),+ code("block_2", null),+ ];++ const { nodes, edges } = getElements(blocks, DEFAULT_SETTINGS, true);+ const saved = getWorkflowBlocks(nodes, edges);++ const innerSaved = saved.find((block) => block.label === "inner");+ const innerBranchA = (+ innerSaved as ConditionalBlock+ ).branch_conditions.find((branch) => branch.id === "inner-a");+ expect(innerBranchA?.next_block_label).toBe("block_1");++ expect(() =>+ validateWorkflowBlocks(saved as Array<WorkflowBlock>),+ ).not.toThrow();+ });+});diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsxindex bdfe1c378..8a117b25f 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsx@@ -52,7 +52,7 @@ function ActionNode({ id, data, type }: NodeProps<ActionNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsxindex 13aa109f8..ee08b1e1a 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsx@@ -46,7 +46,7 @@ function CodeBlockNode({ id, data }: NodeProps<CodeBlockNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/BranchesEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/BranchesEditor.tsxindex 977a9dfcc..dc0d8e33d 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/BranchesEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/BranchesEditor.tsx@@ -20,6 +20,7 @@ import { useWorkflowHasChangesStore } from "@/store/WorkflowHasChangesStore";import { useUpdate } from "../../useUpdate";import { AppNode, isWorkflowBlockNode } from "..";import { updateNodeAndDescendantsVisibility } from "../../workflowEditorUtils";+import { applyEdgeVisibility } from "./applyEdgeVisibility";import {ConditionalNodeData,createBranchCondition,@@ -166,54 +167,11 @@ function BranchesEditor({ nodeId, data }: Props) {return updatedNodes;});- // Toggle edge visibility using callback (needs updated nodes)setEdges((currentEdges) => {- return currentEdges.map((edge) => {- const edgeData = edge.data as- | {- conditionalNodeId?: string;- conditionalBranchId?: string;- }- | undefined;-- // Only affect edges that belong to this conditional and have branch metadata- if (- edgeData?.conditionalNodeId === id &&- edgeData?.conditionalBranchId- ) {- const shouldHide = edgeData.conditionalBranchId !== activeBranchId;- return { ...edge, hidden: shouldHide };- }-- // Hide edges connected to hidden nodes- const sourceNode = updatedNodesSnapshot.find(- (n: AppNode) => n.id === edge.source,- );- const targetNode = updatedNodesSnapshot.find(- (n: AppNode) => n.id === edge.target,- );- if (sourceNode?.hidden || targetNode?.hidden) {- return { ...edge, hidden: true };- }-- // Unhide edges when both nodes are visible, but ONLY if they're not conditional branch edges- // (Conditional branch edges should stay hidden if they're for inactive branches)- if (- sourceNode &&- targetNode &&- !sourceNode.hidden &&- !targetNode.hidden- ) {- const isConditionalBranchEdge =- edgeData?.conditionalNodeId && edgeData?.conditionalBranchId;- if (!isConditionalBranchEdge) {- // Regular edge (e.g., loop's START → adder) - unhide when nodes are visible- return { ...edge, hidden: false };- }- }-- return edge;- });+ const nodeMap = new Map(updatedNodesSnapshot.map((n) => [n.id, n]));+ return currentEdges.map((edge) =>+ applyEdgeVisibility(edge, nodeMap, id, activeBranchId),+ );});// Trigger layout recalculation after visibility changesdiff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/ConditionalNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/ConditionalNode.tsxindex 272d349e5..f197a0d92 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/ConditionalNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/ConditionalNode.tsx@@ -134,7 +134,7 @@ function ConditionalNodeComponent({ id, data }: NodeProps<ConditionalNode>) {/><divclassName={cn(- "w-[30rem] rounded-lg bg-slate-elevation3 px-6 py-4 shadow-sm transition-all motion-reduce:transition-none",+ "w-[30rem] rounded-lg bg-slate-elevation3 px-6 py-4 shadow-sm transition-shadow motion-reduce:transition-none",data.comparisonColor,)}>@@ -176,7 +176,7 @@ function ConditionalNodeComponent({ id, data }: NodeProps<ConditionalNode>) {<divref={headerRef}className={cn(- "w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",data.comparisonColor,)}diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/applyEdgeVisibility.test.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/applyEdgeVisibility.test.tsnew file mode 100644index 000000000..dbd5772b5--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/applyEdgeVisibility.test.ts@@ -0,0 +1,133 @@+import { describe, it, expect } from "vitest";+import type { Edge } from "@xyflow/react";+import { applyEdgeVisibility } from "./applyEdgeVisibility";++const COND_ID = "cond-1";+const BRANCH_A = "branch-a";+const BRANCH_B = "branch-b";++type VisNode = {+ id: string;+ hidden?: boolean;+ type?: string;+ data?: Record<string, unknown>;+};++function edge(+ overrides: Partial<Edge> & { source: string; target: string },+): Edge {+ return {+ id: "e1",+ type: "edgeWithAddButton",+ ...overrides,+ };+}++function toMap(nodes: VisNode[]): Map<string, VisNode> {+ return new Map(nodes.map((n) => [n.id, n]));+}++const EMPTY = new Map<string, VisNode>();++describe("applyEdgeVisibility", () => {+ it("hides edge whose conditionalBranchId differs from active branch", () => {+ const e = edge({+ source: "s",+ target: "t",+ data: { conditionalNodeId: COND_ID, conditionalBranchId: BRANCH_B },+ });+ const result = applyEdgeVisibility(e, EMPTY, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(true);+ });++ it("shows edge whose conditionalBranchId matches active branch", () => {+ const e = edge({+ source: "s",+ target: "t",+ data: { conditionalNodeId: COND_ID, conditionalBranchId: BRANCH_A },+ });+ const result = applyEdgeVisibility(e, EMPTY, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(false);+ });++ it("hides edge when source node is hidden", () => {+ const e = edge({ source: "s", target: "t" });+ const nodes = toMap([+ { id: "s", hidden: true, data: {} },+ { id: "t", hidden: false, data: {} },+ ]);+ const result = applyEdgeVisibility(e, nodes, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(true);+ });++ it("unhides loop START edge when both nodes visible and no branch affinity", () => {+ const e = edge({+ source: "loop-start",+ target: "loop-adder",+ hidden: true,+ });+ const nodes = toMap([+ { id: "loop-start", hidden: false, data: {} },+ { id: "loop-adder", hidden: false, data: {} },+ ]);+ const result = applyEdgeVisibility(e, nodes, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(false);+ });++ it("does NOT unhide edge whose target belongs to inactive branch", () => {+ const e = edge({ source: "start", target: "block-b", hidden: true });+ const nodes = toMap([+ { id: "start", hidden: false, type: "start", data: {} },+ {+ id: "block-b",+ hidden: false,+ data: {+ conditionalNodeId: COND_ID,+ conditionalBranchId: BRANCH_B,+ },+ },+ ]);+ const result = applyEdgeVisibility(e, nodes, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(true);+ });++ it("does NOT unhide edge whose source belongs to inactive branch", () => {+ const e = edge({ source: "block-b", target: "adder", hidden: true });+ const nodes = toMap([+ {+ id: "block-b",+ hidden: false,+ data: {+ conditionalNodeId: COND_ID,+ conditionalBranchId: BRANCH_B,+ },+ },+ { id: "adder", hidden: false, type: "nodeAdder", data: {} },+ ]);+ const result = applyEdgeVisibility(e, nodes, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(true);+ });++ it("ignores branch affinity from a different conditional", () => {+ const e = edge({ source: "start", target: "block-x", hidden: true });+ const nodes = toMap([+ { id: "start", hidden: false, data: {} },+ {+ id: "block-x",+ hidden: false,+ data: {+ conditionalNodeId: "other-cond",+ conditionalBranchId: BRANCH_B,+ },+ },+ ]);+ const result = applyEdgeVisibility(e, nodes, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(false);+ });++ it("preserves edge unchanged when no rules match", () => {+ const e = edge({ source: "unknown", target: "also-unknown", hidden: true });+ const result = applyEdgeVisibility(e, EMPTY, COND_ID, BRANCH_A);+ expect(result.hidden).toBe(true);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/applyEdgeVisibility.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/applyEdgeVisibility.tsnew file mode 100644index 000000000..210d29301--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ConditionalNode/applyEdgeVisibility.ts@@ -0,0 +1,62 @@+import type { Edge } from "@xyflow/react";++type BranchMeta = {+ conditionalNodeId?: string | null;+ conditionalBranchId?: string | null;+};++type VisNode = {+ id: string;+ hidden?: boolean;+ type?: string;+ data?: Record<string, unknown>;+};++/**+ * Priority: branch-affinity match > hidden-node propagation > both-visible non-branch edges.+ */+export function applyEdgeVisibility(+ edge: Edge,+ nodeMap: Map<string, VisNode>,+ conditionalId: string,+ activeBranchId: string,+): Edge {+ const edgeData = edge.data as BranchMeta | undefined;++ if (+ edgeData?.conditionalNodeId === conditionalId &&+ edgeData?.conditionalBranchId+ ) {+ const shouldHide = edgeData.conditionalBranchId !== activeBranchId;+ return { ...edge, hidden: shouldHide };+ }++ const sourceNode = nodeMap.get(edge.source);+ const targetNode = nodeMap.get(edge.target);++ if (sourceNode?.hidden || targetNode?.hidden) {+ return { ...edge, hidden: true };+ }++ if (sourceNode && targetNode && !sourceNode.hidden && !targetNode.hidden) {+ const isConditionalBranchEdge =+ edgeData?.conditionalNodeId && edgeData?.conditionalBranchId;+ if (!isConditionalBranchEdge) {+ const srcBranch =+ sourceNode.data?.conditionalNodeId === conditionalId+ ? sourceNode.data?.conditionalBranchId+ : null;+ const tgtBranch =+ targetNode.data?.conditionalNodeId === conditionalId+ ? targetNode.data?.conditionalBranchId+ : null;+ const srcInactive = srcBranch != null && srcBranch !== activeBranchId;+ const tgtInactive = tgtBranch != null && tgtBranch !== activeBranchId;+ if (!srcInactive && !tgtInactive) {+ return { ...edge, hidden: false };+ }+ }+ }++ return edge;+}diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/DownloadNode/DownloadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/DownloadNode/DownloadNode.tsxindex 3c4e7f2db..a04f27c70 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/DownloadNode/DownloadNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/DownloadNode/DownloadNode.tsx@@ -46,7 +46,7 @@ function DownloadNode({ id, data }: NodeProps<DownloadNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsxindex 68869b059..d8f3166cc 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsx@@ -53,7 +53,7 @@ function ExtractionNode({ id, data, type }: NodeProps<ExtractionNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none bg-slate-950": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsxindex d9c87a57c..1138caaf1 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsx@@ -52,7 +52,7 @@ function FileDownloadNode({ id, data }: NodeProps<FileDownloadNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/FileParserNode/FileParserNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/FileParserNode/FileParserNode.tsxindex f62b60bea..ebed7360d 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/FileParserNode/FileParserNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/FileParserNode/FileParserNode.tsx@@ -46,7 +46,7 @@ function FileParserNode({ id, data }: NodeProps<FileParserNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadNode.tsxindex 175c28e53..c8214c0c7 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/FileUploadNode/FileUploadNode.tsx@@ -46,7 +46,7 @@ function FileUploadNode({ id, data }: NodeProps<FileUploadNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsxindex d2ad47213..6a32e3f42 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx@@ -49,7 +49,7 @@ function GoogleSheetsReadNode({/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsxindex 343269b64..80fc7e8ee 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx@@ -49,7 +49,7 @@ function GoogleSheetsWriteNode({/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/HttpRequestNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/HttpRequestNode.tsxindex dba1c58ed..454fea8f6 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/HttpRequestNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/HttpRequestNode.tsx@@ -48,7 +48,7 @@ function HttpRequestNode({ id, data, type }: NodeProps<HttpRequestNodeType>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/HumanInteractionNode/HumanInteractionNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/HumanInteractionNode/HumanInteractionNode.tsxindex 712b6705c..8c65975d8 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/HumanInteractionNode/HumanInteractionNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/HumanInteractionNode/HumanInteractionNode.tsx@@ -50,7 +50,7 @@ function HumanInteractionNode({/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsxindex 5ee1e3f10..3e47a54bf 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsx@@ -52,7 +52,7 @@ function LoginNode({ id, data, type }: NodeProps<LoginNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsxindex 59049d6a9..f8a26f019 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx@@ -155,7 +155,7 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {/><divclassName={cn(- "w-[30rem] rounded-lg bg-slate-elevation3 px-6 py-4 shadow-sm transition-all motion-reduce:transition-none",+ "w-[30rem] rounded-lg bg-slate-elevation3 px-6 py-4 shadow-sm transition-shadow motion-reduce:transition-none",{"pointer-events-none": thisBlockIsPlaying,"bg-slate-950 outline outline-2 outline-slate-300":@@ -206,7 +206,7 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {<divref={headerRef}className={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsxindex 9f018124a..ee0812eed 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsx@@ -56,7 +56,7 @@ function NavigationNode({ id, data, type }: NodeProps<NavigationNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/PDFParserNode/PDFParserNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/PDFParserNode/PDFParserNode.tsxindex 2ffa71af1..5d10b8d64 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/PDFParserNode/PDFParserNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/PDFParserNode/PDFParserNode.tsx@@ -46,7 +46,7 @@ function PDFParserNode({ id, data }: NodeProps<PDFParserNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/PrintPageNode/PrintPageNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/PrintPageNode/PrintPageNode.tsxindex a69dabe07..ea22d7cca 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/PrintPageNode/PrintPageNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/PrintPageNode/PrintPageNode.tsx@@ -46,7 +46,7 @@ function PrintPageNode({ id, data }: NodeProps<PrintPageNode>) {/><divclassName={cn(- "w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailNode.tsxindex aa4e03aab..b733b6346 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailNode.tsx@@ -46,7 +46,7 @@ function SendEmailNode({ id, data }: NodeProps<SendEmailNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsxindex c14a6dc14..1283740b9 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsx@@ -52,7 +52,7 @@ function TaskNode({ id, data, type }: NodeProps<TaskNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/Taskv2Node/Taskv2Node.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/Taskv2Node/Taskv2Node.tsxindex 335929dcd..69d348227 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/Taskv2Node/Taskv2Node.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/Taskv2Node/Taskv2Node.tsx@@ -50,7 +50,7 @@ function Taskv2Node({ id, data }: NodeProps<Taskv2Node>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow",{"pointer-events-none": thisBlockIsPlaying,"bg-slate-950 outline outline-2 outline-slate-300":diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/TextPromptNode/TextPromptNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/TextPromptNode/TextPromptNode.tsxindex 07e3ce368..e2c29d7f0 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/TextPromptNode/TextPromptNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/TextPromptNode/TextPromptNode.tsx@@ -46,7 +46,7 @@ function TextPromptNode({ id, data }: NodeProps<TextPromptNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/URLNode/URLNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/URLNode/URLNode.tsxindex bff666039..3aebb2d6d 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/URLNode/URLNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/URLNode/URLNode.tsx@@ -52,7 +52,7 @@ function URLNode({ id, data }: NodeProps<URLNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/UploadNode/UploadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/UploadNode/UploadNode.tsxindex 081bb2ef8..29f31d6b1 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/UploadNode/UploadNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/UploadNode/UploadNode.tsx@@ -40,7 +40,7 @@ function UploadNode({ id, data }: NodeProps<UploadNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsxindex 9c7bc2fca..51b8c6d02 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx@@ -52,7 +52,7 @@ function ValidationNode({ id, data, type }: NodeProps<ValidationNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/WaitNode/WaitNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/WaitNode/WaitNode.tsxindex 0efd2c239..4de2b9b0c 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/WaitNode/WaitNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/WaitNode/WaitNode.tsx@@ -46,7 +46,7 @@ function WaitNode({ id, data, type }: NodeProps<WaitNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsxindex a2c3d7de6..f85e0cb74 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsx@@ -47,7 +47,7 @@ function WorkflowTriggerNode({ id, data }: NodeProps<WorkflowTriggerNodeType>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.tsindex 6082bb1c6..3763b041f 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts@@ -235,23 +235,26 @@ function layoutUtil(edges: Array<Edge>,options: Dagre.configUnion = {},allNodes?: Array<AppNode>,+ heightOverrides?: Map<string, number>,): { nodes: Array<AppNode>; edges: Array<Edge> } {const g = new Dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({}));g.setGraph({ rankdir: "TB", ...options });edges.forEach((edge) => g.setEdge(edge.source, edge.target));nodes.forEach((node) => {- // For loop/conditional nodes without measurements, use computed width- let width = node.measured?.width ?? 0;- let height = node.measured?.height ?? 0;+ let width = measuredOr(node.measured?.width, DEFAULT_BLOCK_WIDTH);+ let height =+ heightOverrides?.get(node.id) ??+ measuredOr(node.measured?.height, DEFAULT_BLOCK_HEIGHT);if ((node.type === "loop" || node.type === "conditional") &&!node.measured?.width) {- // Use full nodes array for nesting calculationwidth = getLoopNodeWidth(node, allNodes ?? nodes);- height = 300; // Reasonable default height+ if (!heightOverrides?.has(node.id)) {+ height = 300;+ }}g.setNode(node.id, {@@ -266,10 +269,12 @@ function layoutUtil(return {nodes: nodes.map((node) => {const dagreNode = g.node(node.id);- // We are shifting the dagre node position (anchor=center center) to the top left- // so it matches the React Flow node anchor point (top left).- const x = dagreNode.x - (node.measured?.width ?? 0) / 2;- const y = dagreNode.y - (node.measured?.height ?? 0) / 2;+ // Use the same dimensions that were fed to Dagre so center-to-topleft+ // conversion is consistent with the layout.+ const nodeWidth = dagreNode.width as number;+ const nodeHeight = dagreNode.height as number;+ const x = dagreNode.x - nodeWidth / 2;+ const y = dagreNode.y - nodeHeight / 2;return { ...node, position: { x, y } };}),@@ -372,6 +377,15 @@ export function updateNodeAndDescendantsVisibility(return result;}+// w-[30rem] = 480px - the standard width for leaf block cards.+const DEFAULT_BLOCK_WIDTH = 480;+// Approximate rendered height of a typical leaf block card (header + one field + padding).+const DEFAULT_BLOCK_HEIGHT = 200;++function measuredOr(value: number | undefined, fallback: number): number {+ return value && value > 0 ? value : fallback;+}+export function getLoopNodeWidth(node: AppNode, nodes: Array<AppNode>): number {const maxNesting = maxNestingLevel(nodes);const nestingLevel = getNestingLevel(node, nodes);@@ -400,122 +414,113 @@ function layout(edges: Array<Edge>,targettedBlockLabel?: string,): { nodes: Array<AppNode>; edges: Array<Edge> } {- const loopNodes = nodes.filter(- (node) => node.type === "loop" && !node.hidden,+ // Computed heights for containers after laying out their children.+ // Propagated to parent layouts so Dagre uses accurate heights instead+ // of stale measured values from the previous render cycle.+ const computedHeights = new Map<string, number>();++ // Collect all container nodes (loops + conditionals), sorted deepest+ // first so child containers are laid out before their parents.+ const containerNodes = nodes.filter(+ (node) =>+ (node.type === "loop" || node.type === "conditional") && !node.hidden,);- const loopNodeChildren: Array<Array<AppNode>> = loopNodes.map(() => []);+ containerNodes.sort((a, b) => {+ return getNestingLevel(b, nodes) - getNestingLevel(a, nodes);+ });++ const containerChildrenMap = new Map<string, Array<AppNode>>();- loopNodes.forEach((node, index) => {+ containerNodes.forEach((node) => {const childNodes = nodes.filter((n) => n.parentId === node.id && !n.hidden);const childNodeIds = new Set(childNodes.map((child) => child.id));- // Include edges even if marked hidden, as long as both nodes are visible- // (edges might be hidden from branch switches but need to be used for layout)+const childEdges = edges.filter((edge) => childNodeIds.has(edge.source) && childNodeIds.has(edge.target),);- const maxChildWidth = Math.max(- ...childNodes.map((node) => node.measured?.width ?? 0),- );- const loopNodeWidth = getLoopNodeWidth(node, nodes);- // Reset child positions to (0,0) before layout to avoid stale positions- const childNodesWithResetPositions = childNodes.map((n) => ({- ...n,- position: { x: 0, y: 0 },- }));- // Check if this loop node is the targetted block (being debugged)- // If so, add extra margin to account for the status row that appears- const nodeLabel = isWorkflowBlockNode(node) ? node.data.label : undefined;- const isTargetted =- targettedBlockLabel && nodeLabel === targettedBlockLabel;- // Use measured header height when available, fall back to 225 for initial render.- // Add 28px to account for outer container (border-2 + p-2 = 10px) + gap (16px) + buffer.- const headerHeight = isLoopNode(node) ? node.data._headerHeight : undefined;- const baseMargin = headerHeight ? headerHeight + 28 : 225;- // Only add extra margin for the status row when using the fallback height,- // since the measured height already includes the status row content.- const marginy =- isTargetted && !headerHeight- ? baseMargin + TARGETTED_BLOCK_EXTRA_MARGIN- : baseMargin;- const layouted = layoutUtil(- childNodesWithResetPositions,- childEdges,- {- marginx: (loopNodeWidth - maxChildWidth) / 2,- marginy,- },- nodes,- );- loopNodeChildren[index] = layouted.nodes;- });- const conditionalNodes = nodes.filter(- (node) => node.type === "conditional" && !node.hidden,- );- const conditionalNodeChildren: Array<Array<AppNode>> = conditionalNodes.map(- () => [],- );+ const containerWidth =+ node.type === "loop" || node.type === "conditional"+ ? getLoopNodeWidth(node, nodes)+ : DEFAULT_BLOCK_WIDTH;- conditionalNodes.forEach((node, index) => {- const childNodes = nodes.filter((n) => n.parentId === node.id && !n.hidden);- const childNodeIds = new Set(childNodes.map((child) => child.id));- // Include edges, but skip hidden edges completely (they're hidden for a reason - inactive branches)- const childEdges = edges.filter((edge) => {- if (!childNodeIds.has(edge.source) || !childNodeIds.has(edge.target)) {- return false;- }- // Exclude hidden edges from layout- if (edge.hidden) {- return false;- }- return true;- });- // Use computed width for loop nodes, measured width for othersconst maxChildWidth = Math.max(...childNodes.map((child) =>- child.type === "loop"+ child.type === "loop" || child.type === "conditional"? getLoopNodeWidth(child, nodes)- : (child.measured?.width ?? 0),+ : measuredOr(child.measured?.width, DEFAULT_BLOCK_WIDTH),),);- const conditionalNodeWidth = getLoopNodeWidth(node, nodes);- // Reset child positions to (0,0) before layout to avoid stale positionsconst childNodesWithResetPositions = childNodes.map((n) => ({...n,position: { x: 0, y: 0 },}));- // Check if this conditional node is the targetted block (being debugged)- // If so, add extra margin to account for the status row that appearsconst nodeLabel = isWorkflowBlockNode(node) ? node.data.label : undefined;const isTargetted =targettedBlockLabel && nodeLabel === targettedBlockLabel;- // Use measured header height when available, fall back to 225 for initial render.- // Add 28px to account for outer container (border-2 + p-2 = 10px) + gap (16px) + buffer.- const conditionalHeaderHeight = isConditionalNode(node)- ? node.data._headerHeight- : undefined;- const conditionalBaseMargin = conditionalHeaderHeight- ? conditionalHeaderHeight + 28- : 225;- // Only add extra margin for the status row when using the fallback height,- // since the measured height already includes the status row content.- const marginy =- isTargetted && !conditionalHeaderHeight- ? conditionalBaseMargin + TARGETTED_BLOCK_EXTRA_MARGIN- : conditionalBaseMargin;++ let baseMargin: number;+ if (node.type === "loop" && isLoopNode(node)) {+ const headerHeight = node.data._headerHeight;+ baseMargin = headerHeight ? headerHeight + 28 : 225;+ if (isTargetted && !headerHeight) {+ baseMargin += TARGETTED_BLOCK_EXTRA_MARGIN;+ }+ } else if (node.type === "conditional" && isConditionalNode(node)) {+ const headerHeight = node.data._headerHeight;+ baseMargin = headerHeight ? headerHeight + 28 : 225;+ if (isTargetted && !headerHeight) {+ baseMargin += TARGETTED_BLOCK_EXTRA_MARGIN;+ }+ } else {+ baseMargin = 225;+ }+const layouted = layoutUtil(childNodesWithResetPositions,childEdges,{- marginx: (conditionalNodeWidth - maxChildWidth) / 2,- marginy,+ marginx: (containerWidth - maxChildWidth) / 2,+ marginy: baseMargin,},nodes,+ computedHeights,);- conditionalNodeChildren[index] = layouted.nodes;+ const centeredChildren = layouted.nodes.map((n) => {+ const nodeWidth =+ (n.type === "loop" || n.type === "conditional") && !n.measured?.width+ ? getLoopNodeWidth(n, nodes)+ : measuredOr(n.measured?.width, DEFAULT_BLOCK_WIDTH);+ return {+ ...n,+ position: {+ x: (containerWidth - nodeWidth) / 2,+ y: n.position.y,+ },+ };+ });++ containerChildrenMap.set(node.id, centeredChildren);++ // Only override the container's height when it has visible children.+ // Collapsed containers have all children hidden; their measured.height+ // (the collapsed card) is already correct and must not be replaced.+ if (centeredChildren.length > 0) {+ let maxChildBottom = 0;+ for (const child of centeredChildren) {+ const childHeight =+ computedHeights.get(child.id) ??+ measuredOr(child.measured?.height, DEFAULT_BLOCK_HEIGHT);+ const bottom = child.position.y + childHeight;+ if (bottom > maxChildBottom) {+ maxChildBottom = bottom;+ }+ }+ computedHeights.set(node.id, maxChildBottom + 24);+ }});const topLevelNodes = nodes.filter((node) => !node.parentId && !node.hidden);@@ -554,15 +559,19 @@ function layout(layoutEdges.concat(syntheticEdges),{},nodes,+ computedHeights,);// Collect all hidden nodes to preserve themconst hiddenNodes = nodes.filter((node) => node.hidden);// Combine all layouted nodes and sort by nesting depth to ensure parents come before children- const allLayoutedNodes = topLevelNodesLayout.nodes- .concat(conditionalNodeChildren.flat())- .concat(loopNodeChildren.flat());+ const allContainerChildren: Array<AppNode> = [];+ for (const children of containerChildrenMap.values()) {+ allContainerChildren.push(...children);+ }+ const allLayoutedNodes =+ topLevelNodesLayout.nodes.concat(allContainerChildren);// Sort by depth: top-level first, then depth-1, depth-2, etc.const nodeDepths = new Map<string, number>();@@ -1488,6 +1497,49 @@ function collectLabelsForBranch(return labels;}+// Labels at or before `targetLabel` in execution order: the conditional itself+// plus every block that can reach it via next_block_label / branch references.+// Branch collection excludes these so a back-reference chain cannot pull the+// conditional (or an earlier block) into its own branch (SKY-8216). Computed+// from the graph rather than array position so it is independent of the order+// branch children happen to be serialized in (SKY-10460).+function labelsAtOrBeforeConditional(+ targetLabel: string,+ blocks: Array<WorkflowBlock>,+): Set<string> {+ const present = new Set(blocks.map((block) => block.label));+ const predecessors = new Map<string, Array<string>>();+ const addEdge = (from: string, to: string | null | undefined): void => {+ if (!to || !present.has(to)) {+ return;+ }+ const list = predecessors.get(to) ?? [];+ list.push(from);+ predecessors.set(to, list);+ };+ for (const block of blocks) {+ addEdge(block.label, block.next_block_label);+ if (block.block_type === "conditional") {+ for (const branch of (block as ConditionalBlock).branch_conditions) {+ addEdge(block.label, branch.next_block_label);+ }+ }+ }++ const result = new Set<string>([targetLabel]);+ const queue = [targetLabel];+ while (queue.length > 0) {+ const label = queue.shift()!;+ for (const pred of predecessors.get(label) ?? []) {+ if (!result.has(pred)) {+ result.add(pred);+ queue.push(pred);+ }+ }+ }+ return result;+}+/*** Reconstructs the proper hierarchical structure for conditional blocks from a flat blocks array.* This is the deserialization counterpart to the edge-based serialization logic.@@ -1521,7 +1573,7 @@ function reconstructConditionalStructure(});// Process each conditional block- blocks.forEach((block, blockIndex) => {+ blocks.forEach((block) => {if (block.block_type !== "conditional") {if (isNestedLoopWorkflowBlock(block)) {// Recursively handle conditionals inside loops@@ -1550,15 +1602,7 @@ function reconstructConditionalStructure(return;}- // Blocks at or before this conditional must not be collected as branch- // children. Without this guard, next_block_label chains that loop back- // to earlier blocks (e.g. reporting → fetch_token) would pull the- // conditional itself into its own branch, setting parentId to its own id- // and crashing React Flow with a stack overflow.- const excludeLabels = new Set<string>();- for (let i = 0; i <= blockIndex; i++) {- excludeLabels.add(blocks[i]!.label);- }+ const excludeLabels = labelsAtOrBeforeConditional(block.label, blocks);// Create START and NodeAdder nodes for this conditionalconst startNodeId = nanoid();@@ -1974,14 +2018,12 @@ function getElements(// conditional's own edges).const branchLabels = new Set<string>();const collectBranchLabels = (loopChildren: Array<WorkflowBlock>) => {- loopChildren.forEach((child, childIndex) => {+ loopChildren.forEach((child) => {if (child.block_type === "conditional") {- // Exclude labels at or before this conditional to prevent- // back-reference chains from pulling in earlier blocks- const loopExclude = new Set<string>();- for (let i = 0; i <= childIndex; i++) {- loopExclude.add(loopChildren[i]!.label);- }+ const loopExclude = labelsAtOrBeforeConditional(+ child.label,+ loopChildren,+ );child.branch_conditions.forEach((branch) => {collectLabelsForBranch(branch.next_block_label,@@ -2128,25 +2170,17 @@ function getElements(}}- // Determine the initial active branch for each conditional node (default branch if available)- const conditionalBlocks = blocks.filter(- (b) => b.block_type === "conditional",- );+ // Determine the initial active branch for each conditional node.+ // Walk the nodes array (not blocks) so nested conditionals inside+ // loops or other conditionals are included.const conditionalNodeToActiveBranch = new Map<string, string>();- conditionalBlocks.forEach((block) => {- const conditionalBlock = block as ConditionalBlock;- const conditionalNode = labelToNode.get(block.label);- if (!conditionalNode) {+ nodes.forEach((node) => {+ if (!isConditionalNode(node)) {return;}- const defaultBranch =- conditionalBlock.branch_conditions.find((branch) => branch.is_default) ??- null;- // Prefer the first branch for initial selection to align with UI expectations- const activeBranch =- conditionalBlock.branch_conditions[0]?.id ?? defaultBranch?.id ?? null;+ const activeBranch = node.data.activeBranchId;if (activeBranch) {- conditionalNodeToActiveBranch.set(conditionalNode.id, activeBranch);+ conditionalNodeToActiveBranch.set(node.id, activeBranch);}});diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.test.ts b/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.test.tsindex ca17dd0a2..1e906d661 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.test.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.test.ts@@ -196,4 +196,59 @@ describe("findBranchContextForInsertion", () => {),).toEqual(branch);});++ it("uses the inner conditional's active branch when inserting into a nested conditional", () => {+ // SKY-10460: a conditional nested inside another conditional carries its+ // own membership metadata (conditionalNodeId/conditionalBranchId pointing+ // at the OUTER conditional). Inserting into the inner conditional's empty+ // branch starts from its START node and walks up to the inner conditional;+ // the context must be the inner conditional's active branch, not its+ // membership in the outer conditional, or the inserted block is orphaned.+ expect(+ findBranchContextForInsertion(+ [+ {+ id: "outer-conditional",+ type: "conditional",+ data: {+ activeBranchId: "outer-branch-a",+ branches: [{ id: "outer-branch-a" }, { id: "outer-branch-b" }],+ label: "outer",+ mergeLabel: null,+ },+ },+ {+ id: "inner-conditional",+ parentId: "outer-conditional",+ type: "conditional",+ data: {+ // Membership in the OUTER conditional.+ conditionalNodeId: "outer-conditional",+ conditionalBranchId: "outer-branch-a",+ conditionalLabel: "outer",+ conditionalMergeLabel: null,+ // The inner conditional's own branch state.+ activeBranchId: "inner-branch-a",+ branches: [{ id: "inner-branch-a" }, { id: "inner-branch-b" }],+ label: "inner",+ mergeLabel: null,+ },+ },+ {+ id: "inner-start",+ parentId: "inner-conditional",+ type: "start",+ data: {},+ },+ ],+ "inner-start",+ "inner-conditional",+ ),+ ).toEqual({+ branchId: "inner-branch-a",+ conditionalLabel: "inner",+ conditionalNodeId: "inner-conditional",+ mergeLabel: null,+ });+ });});diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.ts b/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.tsindex 318b23d12..645e27e57 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowInsertion.ts@@ -89,6 +89,22 @@ export function findBranchContextForInsertion(return undefined;}+ // A conditional we are inserting INTO contributes its own active branch,+ // not its membership in a parent conditional. A nested conditional node+ // carries both: its conditionalNodeId/conditionalBranchId point at the+ // outer conditional, while branchContextFromConditionalNode reads its own+ // active branch. Check the container context first so the inner branch+ // wins and the inserted block is not orphaned under the outer conditional+ // (SKY-10460).+ const treatConditionalAsContainer =+ includeStartingConditional || !isStartingNode;+ if (treatConditionalAsContainer) {+ const conditionalBranchContext = branchContextFromConditionalNode(node);+ if (conditionalBranchContext) {+ return conditionalBranchContext;+ }+ }+const nodeBranchContext = branchContextFromNodeData(node.data as Partial<NodeBaseData> | undefined,);@@ -96,13 +112,6 @@ export function findBranchContextForInsertion(return nodeBranchContext;}- const conditionalBranchContext =- (includeStartingConditional || !isStartingNode) &&- branchContextFromConditionalNode(node);- if (conditionalBranchContext) {- return conditionalBranchContext;- }-isStartingNode = false;currentId = node.parentId;}