Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-11608): restore syntax highlighting on large webhook payloads (#6967)
Aaron Perez798689d76d39
diff --git a/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsx b/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsxindex b3b536c2e..e00db823f 100644--- a/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsx+++ b/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsx@@ -1,7 +1,10 @@import { render } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it } from "vitest";import { CodeEditor } from "./CodeEditor";-import { isOversizedDocument } from "./oversizedDocument";+import {+ isDeeplyNestedDocument,+ isOversizedDocument,+} from "./oversizedDocument";// CodeEditor mounts the real editor immediately only when IntersectionObserver// is absent; otherwise it renders a lazy-mount placeholder with no `.cm-content`.@@ -43,6 +46,18 @@ function deeplyNestedJson(depth: number): string {return "[".repeat(depth) + "1" + "]".repeat(depth);}+// Big enough to cross LARGE_DOCUMENT_CHAR_THRESHOLD (50k) but structurally+// shallow (depth ~3), like a data-heavy webhook payload. These are safe to+// highlight — CodeMirror renders/highlights only the visible viewport, and the+// SKY-11432 overflow is driven by decoration nesting depth, not raw size.+function largeShallowJson(): string {+ const items = Array.from({ length: 4000 }, (_, i) => ({+ id: i,+ name: `item-${i}`,+ }));+ return JSON.stringify({ items }, null, 2);+}+describe("isOversizedDocument", () => {it("treats small, shallow JSON as normal", () => {const value = JSON.stringify({ a: 1, b: [1, 2, 3], c: "hi" }, null, 2);@@ -73,6 +88,32 @@ describe("isOversizedDocument", () => {});});+describe("isDeeplyNestedDocument", () => {+ it("treats small, shallow JSON as not deeply nested", () => {+ const value = JSON.stringify({ a: 1, b: [1, 2, 3], c: "hi" }, null, 2);+ expect(isDeeplyNestedDocument(value)).toBe(false);+ });++ it("does not flag large but shallow JSON (keeps highlighting)", () => {+ const value = largeShallowJson();+ expect(value.length).toBeGreaterThan(50_000);+ expect(isDeeplyNestedDocument(value)).toBe(false);+ });++ it("flags deeply nested JSON beyond the depth cap", () => {+ expect(isDeeplyNestedDocument(deeplyNestedJson(250))).toBe(true);+ });++ it("does not flag moderately nested JSON within the depth cap", () => {+ expect(isDeeplyNestedDocument(deeplyNestedJson(20))).toBe(false);+ });++ it("treats an absent (undefined/null) document as not deeply nested", () => {+ expect(isDeeplyNestedDocument(undefined)).toBe(false);+ expect(isDeeplyNestedDocument(null)).toBe(false);+ });+});+describe("CodeEditor large-document guard", () => {it("highlights and wraps normal JSON", () => {const value = JSON.stringify({ a: 1, b: [1, 2, 3], c: "hi" }, null, 2);@@ -88,10 +129,10 @@ describe("CodeEditor large-document guard", () => {expect(isLineWrapping(container)).toBe(false);});- it("disables highlighting and wrapping for very large JSON", () => {- const value = `"${"a".repeat(60_000)}"`;+ it("keeps highlighting but disables wrapping for large, shallow JSON", () => {+ const value = largeShallowJson();const { container } = render(<CodeEditor value={value} language="json" />);- expect(highlightTokenSpanCount(container)).toBe(0);+ expect(highlightTokenSpanCount(container)).toBeGreaterThan(0);expect(isLineWrapping(container)).toBe(false);});diff --git a/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx b/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsxindex 7e6468caf..60d633b68 100644--- a/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx@@ -8,7 +8,10 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";import { cn } from "@/util/utils";import { useDebouncedCallback } from "use-debounce";-import { isOversizedDocument } from "./oversizedDocument";+import {+ isDeeplyNestedDocument,+ LARGE_DOCUMENT_CHAR_THRESHOLD,+} from "./oversizedDocument";import "./code-mirror-overrides.css";function getLanguageExtension(language: "python" | "json" | "html") {@@ -150,10 +153,20 @@ function CodeEditorImpl({if (!viewRef.current) viewRef.current = viewUpdate.view;}, []);- const oversized = useMemo(- () => isOversizedDocument(internalValue),+ // Highlighting is only unsafe for deeply nested documents (the stack-overflow+ // trigger); line-wrapping is additionally guarded by raw size. Keeping these+ // separate lets large-but-shallow payloads (e.g. webhook bodies) stay+ // syntax-highlighted while still rendering unwrapped. See SKY-11432 / SKY-11608.+ const deeplyNested = useMemo(+ () => isDeeplyNestedDocument(internalValue),[internalValue],);+ // Reuses deeplyNested's scan instead of calling isOversizedDocument, which+ // would re-run getMaxStructureDepth for values under the size threshold.+ const oversized = useMemo(+ () => internalValue.length > LARGE_DOCUMENT_CHAR_THRESHOLD || deeplyNested,+ [internalValue, deeplyNested],+ );const effectiveLineWrap = lineWrap && !oversized;// Memoize the extension tuple so React hands CodeMirror a stable@@ -162,7 +175,7 @@ function CodeEditorImpl({// unnecessary editor state reconfiguration.const extensions = useMemo<Extension[]>(() => {const exts: Extension[] = [];- if (language && !oversized) {+ if (language && !deeplyNested) {exts.push(getLanguageExtension(language));}if (effectiveLineWrap) {@@ -175,7 +188,7 @@ function CodeEditorImpl({exts.push(fullHeightExtension);}return exts;- }, [language, oversized, effectiveLineWrap, extraExtensions, fullHeight]);+ }, [language, deeplyNested, effectiveLineWrap, extraExtensions, fullHeight]);const style: React.CSSProperties = { fontSize };if (fullHeight) {diff --git a/skyvern-frontend/src/routes/workflows/components/oversizedDocument.ts b/skyvern-frontend/src/routes/workflows/components/oversizedDocument.tsindex 41206de76..319d62858 100644--- a/skyvern-frontend/src/routes/workflows/components/oversizedDocument.ts+++ b/skyvern-frontend/src/routes/workflows/components/oversizedDocument.ts@@ -1,4 +1,4 @@-const LARGE_DOCUMENT_CHAR_THRESHOLD = 50_000;+export const LARGE_DOCUMENT_CHAR_THRESHOLD = 50_000;const MAX_STRUCTURE_DEPTH = 200;function getMaxStructureDepth(text: string, cap: number): number {@@ -38,10 +38,21 @@ function getMaxStructureDepth(text: string, cap: number): number {}/**- * Large or deeply nested documents drive CodeMirror's view-layer RangeSet scan- * and line-wrapping measurement into per-level recursion that overflows the- * call stack (SKY-11432). Above these bounds the editor falls back to plain,- * unwrapped text instead of syntax-highlighted, wrapped rendering.+ * Deeply nested JSON drives CodeMirror's view-layer RangeSet scan into+ * per-level recursion that overflows the call stack.+ */+export function isDeeplyNestedDocument(+ value: string | null | undefined,+): boolean {+ if (typeof value !== "string") {+ return false;+ }+ return getMaxStructureDepth(value, MAX_STRUCTURE_DEPTH) > MAX_STRUCTURE_DEPTH;+}++/**+ * Large or deeply nested documents drive CodeMirror's line-wrapping measurement+ * into per-level recursion / expensive reflow.*/export function isOversizedDocument(value: string | null | undefined): boolean {if (typeof value !== "string") {@@ -50,5 +61,5 @@ export function isOversizedDocument(value: string | null | undefined): boolean {if (value.length > LARGE_DOCUMENT_CHAR_THRESHOLD) {return true;}- return getMaxStructureDepth(value, MAX_STRUCTURE_DEPTH) > MAX_STRUCTURE_DEPTH;+ return isDeeplyNestedDocument(value);}