Skip to content

Fix listener snapshots before singular event handlers - #804

Open
er-s-an wants to merge 1 commit into
modelcontextprotocol:mainfrom
er-s-an:fix/dispatch-handler-listener-snapshot-20261011
Open

er-s-an wants to merge 1 commit into
modelcontextprotocol:mainfrom
er-s-an:fix/dispatch-handler-listener-snapshot-20261011

Conversation

@er-s-an

@er-s-an er-s-an commented Oct 11, 2026

Copy link
Copy Markdown

Summary

Capture the event listener snapshot before invoking the singular on* handler. This makes mutations from that handler obey the same documented next-dispatch behavior as mutations from addEventListener listeners.

Previously, an on* handler that added a listener caused that new listener to receive the event already in progress. Removing a listener from the handler caused it to miss the current event. Both contradicted EventDispatcher.dispatch()'s documented snapshot contract. This affects the shared notification fan-out used by App and AppBridge.

The fix preserves handler-first invocation and listener insertion order. The two regression tests verify both the current and subsequent dispatch.

Verification

  • New regression tests against unchanged upstream: 2 failures, 4 existing tests passed.
  • After fix: 247 SDK tests passed, 0 failed (bun test ./src/*.test.ts ./src/server/*.test.ts).
  • tsc --noEmit passed.
  • Prettier check of both changed files passed.
  • git diff --check passed.
  • Full build was attempted but blocked by this execution environment denying the tsx IPC socket (listen EPERM); no successful build or browser/E2E run is claimed.
  • Running the broader bun test src also discovered a PDF example test without its workspace dependency @cantoo/pdf-lib; the scoped SDK suite above passes.

AI assistance was used for diagnosis, implementation and test preparation. The change was checked against fresh local regression results; no remote model APIs were needed.

@er-s-an
er-s-an marked this pull request as ready for review October 12, 2026 12:35

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant