Skip to content

Fix app dev exiting on non-JSON extensions WebSocket messages - #9040

Open
isaacroldan wants to merge 1 commit into
mainfrom
torrent/cli-2-app-dev-crashes-when-an-extensions-webso
Open

isaacroldan wants to merge 1 commit into
mainfrom
torrent/cli-2-app-dev-crashes-when-an-extensions-webso

Conversation

@isaacroldan

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

shopify app dev exits when a client of the /extensions WebSocket sends a text message that is not valid JSON. getOnMessageHandler in packages/app/src/cli/services/dev/extension/websocket/handlers.ts calls JSON.parse on every message without a try/catch. The SyntaxError escapes the socket's message listener as an uncaught exception, and the process stops.

WHAT is this pull request doing?

  • Catches the SyntaxError from JSON.parse, logs it with outputDebug, and ignores the message. Other errors still propagate.
  • Adds a regression test in handlers.test.ts for a message that is not JSON.
  • Adds a patch changeset for @shopify/app.

Before, a client that sends not json stops the dev session:

SyntaxError: Unexpected token 'o', "not json" is not valid JSON

After, the session continues. With --verbose, the CLI prints:

Ignoring websocket message that is not valid JSON: Unexpected token 'o', "not json" is not valid JSON

How to manually test your changes?

  1. Run shopify app dev --verbose in an app with a UI extension.
  2. Connect a WebSocket client to the dev server at /extensions, for example npx wscat -c ws://localhost:<port>/extensions.
  3. Send the text not json.
  4. Confirm that app dev keeps running and prints the debug line above.
  5. Send a valid message, for example {"event":"dispatch","data":{"type":"focus","extensions":[]}}, and confirm that the connected clients receive it.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

getOnMessageHandler called JSON.parse on every incoming message without
a try/catch. When a client sent a text message that is not valid JSON,
the SyntaxError escaped the socket's message listener as an uncaught
exception and `app dev` exited.

Catch the SyntaxError, log it with outputDebug, and ignore the message.
Add a regression test in handlers.test.ts.

Co-authored-by: Isaac Roldan <isaac.roldan@shopify.com>
@github-actions github-actions Bot added the Area: @shopify/app @shopify/app package issues label Oct 29, 2026
@isaacroldan
isaacroldan marked this pull request as ready for review October 29, 2026 12:14
@isaacroldan
isaacroldan requested a review from a team as a code owner October 29, 2026 12:14

This branch has not been deployed

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

Labels

Area: @shopify/app @shopify/app package issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant