Skip to content

fix(vite): suppress aborted errors on HTTP/2 client disconnect - #4773

Merged
pi0 merged 4 commits into
nitrojs:mainfrom
lx3133584:fix/vite-dev-http2-client-disconnect
Oct 14, 2026
Merged

pi0 merged 4 commits into
nitrojs:mainfrom
lx3133584:fix/vite-dev-http2-client-disconnect

Conversation

@lx3133584

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #4772

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

Problem

When running Vite dev server over HTTP/2 (e.g. when server.https is configured, or under an HTTP/2 reverse proxy), client request cancellation (such as navigation during a pending POST body upload) causes Vite error middleware to receive an aborted request error and log Internal server error: This operation was aborted, broadcasting error overlays to connected browser tabs. Over HTTP/1.1 this was suppressed in #4708, but HTTP/2 remained unhandled.

Root Cause

In Node.js node:http2, Http2ServerResponse instances do not expose a destroyed property directly (it evaluates to undefined), whereas their underlying ServerHttp2Stream instance (res.stream) tracks cancellation via res.stream.destroyed. In src/build/vite/dev.ts, the check if (nodeRes.destroyed) return; evaluates to undefined (falsy) on HTTP/2 responses, causing client-aborted errors to be forwarded to next(error).

Fix

Introduced isResponseDestroyed(res) in src/build/vite/dev.ts that checks both res.destroyed (for HTTP/1.1 ServerResponse) and ("stream" in res && res.stream?.destroyed) (for HTTP/2 Http2ServerResponse). When either is destroyed, the error is safely suppressed from forwarding to Vite.

Testing

Added unit tests in test/unit/vite-dev-client-disconnect.test.ts verifying isResponseDestroyed correctly identifies destroyed and active states for both standard Node.js ServerResponse and HTTP/2 Http2ServerResponse stream objects.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@lx3133584
lx3133584 requested a review from pi0 as a code owner October 13, 2026 16:37
@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown

@lx3133584 is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5dc259bc-3768-4324-89ee-e34f7f0b3324
📥 Commits

Reviewing files that changed from the base of the PR and between 2d83506 and 10744fe.

📒 Files selected for processing: 1
  • src/build/vite/dev.ts
 _____________________________________________
< Assembling the Avengers to fight your bugs. >
 ---------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a17dc681-4062-4242-a1cc-1320706159a3
📥 Commits

Reviewing files that changed from the base of the PR and between c76ede4 and 2d83506.

📒 Files selected for processing (2)
  • src/build/vite/dev.ts
  • test/unit/vite-dev-client-disconnect.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The Vite development middleware now checks both the response’s destroyed property and its associated stream’s destroyed property. Tests cover HTTP/1.1 and HTTP/2 response states.

Changes: Vite client-disconnect handling

Layer / File(s) Summary
Response destruction check
src/build/vite/dev.ts, test/unit/vite-dev-client-disconnect.test.ts
The middleware uses the exported isResponseDestroyed helper to check response and stream destruction. Tests cover HTTP/1.1 and HTTP/2 values, including absent or undefined properties and undestroyed responses.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2d835

The middleware now suppresses errors for destroyed responses and streams. No actionable issue remains that should prevent merging.

### Architecture Summary

Architecture risk: 🔵 Low · up to 2d835

The change affects 2 systems.

Changed systems: src, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/build/vite/dev.ts: The middleware’s error path now checks isResponseDestroyed(nodeRes) instead of checking only nodeRes.destroyed, also accounting for a destroyed response stream.
  • observed — Modified behavior in src/build/vite/dev.ts: Adds the exported isResponseDestroyed helper, which returns true if the response or its optional stream is marked destroyed.
  • observed — Modified behavior in test/unit/vite-dev-client-disconnect.test.ts: Imports Vitest test functions and isResponseDestroyed for the new test suite.
  • observed — Modified behavior in test/unit/vite-dev-client-disconnect.test.ts: Adds tests expecting isResponseDestroyed to reflect HTTP/1.1 destroyed values and HTTP/2 stream.destroyed values, including when the response property is undefined or absent. Also expects false for an empty response and an undestroyed response with no stream.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title follows Conventional Commits format with the fix(vite): prefix and accurately describes the HTTP/2 client-disconnect fix.
Description check Passed The description clearly explains the HTTP/2 aborted-error problem, root cause, implementation, linked issue, and tests. It is directly related to the changeset.
Linked Issues check Passed The PR meets the coding requirements in #4772. nitroDevMiddleware now returns from its error handler when isResponseDestroyed(nodeRes) is true. The helper checks both res.destroyed for HTTP/1.1 …
Out of Scope Changes check Passed The reviewed changes stay within #4772. They add the response-destruction check in src/build/vite/dev.ts and focused unit tests in test/unit/vite-dev-client-disconnect.test.ts. These changes direc…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4773

commit: 5c5f252

@pi0
pi0 merged commit 9350ff5 into nitrojs:main Oct 14, 2026
3 of 5 checks passed
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.

vite dev: the client-disconnect check from #4708 misses HTTP/2 (server.https)

2 participants