Skip to content

Conversation

@adailey-sw
Copy link

Problem

The code editor crashes with an infinite loop when typing specific expressions with boolean expected types.

Reproduction steps:

  1. Open the "Controlled" story for CodeEditor in Storybook
  2. Set expectedVariableType to true (boolean type)
  3. Type filter([], ) in the editor
  4. When adding the space after the comma, the browser freezes and eventually crashes

Root Cause

The crash is caused by invalid diagnostic span data returned from the WASM type checking system. Specifically, when the zen-engine-wasm performs type checking on the expression filter([], ) with a boolean expected type, it returns a diagnostic with:

{
  "from": 11,
  "to": 10,
  "severity": "warning",
  "message": "Invalid syntax at (10, 10)",
  "source": "Type check"
}

The invalid span where from > to (from: 11, to: 10) causes CodeMirror's internal diagnostic processing to enter an infinite loop.

Solution

Added validation in the validateZenExpression function to ensure diagnostic spans are always valid before passing them to CodeMirror:

// Ensure span values are valid to prevent CodeMirror infinite loops
const from = Math.min(t.span[0], t.span[1]);
const to = Math.max(t.span[0], t.span[1]);

This fix ensures that even if the WASM layer returns invalid spans, we create valid diagnostics that CodeMirror can process safely.

Testing

  • ✅ Verified the reproduction case no longer causes crashes
  • ✅ Confirmed normal type checking functionality remains intact
  • ✅ Tested with various other expressions and expected types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant