Skip to content

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

Merged
isaacroldan merged 2 commits into
mainfrom
torrent/cli-2-app-dev-crashes-when-an-extensions-webso
Nov 5, 2026
Merged

isaacroldan merged 2 commits 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

@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

@alexanderMontague alexanderMontague left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving — the fix is correct for what it claims. A SyntaxError thrown inside the message listener is an uncaught exception (it never becomes a socket error event, so #9039 doesn't cover it), and rethrowing non-SyntaxErrors is the right call.

One suggestion worth doing here rather than in a third PR: the guard only catches invalid JSON. Valid JSON with the wrong shape still throws a TypeError from the same listener and exits app dev. I checked these against the handler logic:

  • null → Cannot destructure property 'event' of 'jsonData' as it is null
  • {"event":"log"} → Cannot read properties of undefined (reading 'extensionName')
  • {"event":"update"} → Cannot read properties of undefined (reading 'app')

A small extension closes this: after parsing, return early unless jsonData is a non-null object, and treat a missing data on log/update as ignorable.

Process nit: this and #9039 are both branched from main, touch the same two files, and fix the same "misbehaving client kills app dev" problem. I confirmed they merge cleanly together, so this is only a question of whether one PR would be easier to review and release-note.


Generated with Pi. Vetted by Me.

@isaacroldan
isaacroldan added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 5, 2026
@isaacroldan
isaacroldan added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 5, 2026
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>
@isaacroldan
isaacroldan force-pushed the torrent/cli-2-app-dev-crashes-when-an-extensions-webso branch from 3c40fdd to 574eac5 Compare November 5, 2026 14:29
@isaacroldan
isaacroldan added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 96296ce Nov 5, 2026
28 of 29 checks passed
@isaacroldan
isaacroldan deleted the torrent/cli-2-app-dev-crashes-when-an-extensions-webso branch November 5, 2026 15:37
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.

2 participants