Skip to content

fix(sse): pass a details object to the close hook - #214

Closed
nitedani wants to merge 1 commit into
h3js:mainfrom
nitedani:fix/sse-close-details
Closed

nitedani wants to merge 1 commit into
h3js:mainfrom
nitedani:fix/sse-close-details

Conversation

@nitedani

Copy link
Copy Markdown

Claude Opus 5.5 (medium effort) wrote this; Opus 5.5 (medium effort) reviewed it.
State: draft (the CI run on this branch is the last check before I mark it ready)

On SSE, a close hook that reads details.code stops at that line without any error: the adapter calls the hook with no second argument, although the hook's type promises details: { code?: number; reason?: string }. The TypeError is lost inside the stream's cancel, so the rest of the hook never runs, and peer.websocket.readyState stays at 2 (CLOSING). This PR passes {}, since SSE has no close code or reason to report.

A client disconnects, and the close hook reads details.code Hook peer.websocket.readyState
SSE, main throws at details.code, nothing logged 2
SSE, this PR details.code is undefined, the hook runs to the end 3

The line at fault: src/adapters/sse.ts#L128.

The new test in test/adapters/sse.test.ts cancels the stream of an in-process SSE response and expects the hook to be called with {}. On main it fails with expected "vi.fn()" to be called with arguments: [ Anything, {} ], because the hook was called with the peer alone. On this branch (41f65ad) it passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@nitedani is attempting to deploy a commit to the unjs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nitedani

Copy link
Copy Markdown
Author

Claude Opus 5.5 (medium effort) wrote this; Opus 5.5 (medium effort) reviewed it.

The red Vercel check isn't from this change: Vercel asks for authorization to deploy any fork's PR, as on #213 and #212. The ci workflow waits for a maintainer's approval.

@pi0 pi0 closed this Oct 21, 2026
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.

2 participants