Skip to content

fix(node): return NodeHttp1Handler & NodeHttp2Handler from toNodeHandler - #376

Open
SHANNWD wants to merge 1 commit into
h3js:mainfrom
SHANNWD:fix/to-node-handler-type-367
Open

SHANNWD wants to merge 1 commit into
h3js:mainfrom
SHANNWD:fix/to-node-handler-type-367

Conversation

@SHANNWD

@SHANNWD SHANNWD commented Dec 4, 2026 •

Copy link
Copy Markdown

Fixes #367

toNodeHandler() returns a function typed with (NodeServerRequest, NodeServerResponse) that supports both HTTP/1 and HTTP/2, so its return type should be NodeHttp1Handler & NodeHttp2Handler & AdapterMeta rather than the NodeHttpHandler union.

Changes:

  • Update toNodeHandler()'s return type (and internal __nodeHandler return assertion) to NodeHttp1Handler & NodeHttp2Handler & AdapterMeta.
  • Remove the workaround as NodeHttp1Handler casts in test/node-adapters.test.ts, test/node-error-paths.test.ts, and test/node-promises.test.ts.
  • Add a test verifying toNodeHandler() is directly assignable to both node:http's createServer and node:http2's createServer.

Summary by CodeRabbit

  • Improvements
    • Improved TypeScript support for using the Node adapter with both HTTP/1 and HTTP/2 servers, without requiring type casts.
    • Runtime behavior is unchanged.

@SHANNWD
SHANNWD requested a review from pi0 as a code owner December 4, 2026 16:02
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@SHANNWD 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 Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

toNodeHandler now returns a type that combines the Node HTTP/1 and HTTP/2 handler types. Tests pass the inferred result to both server constructors and remove explicit HTTP/1 handler casts.

Changes: Node handler type compatibility

Layer / File(s) Summary
Combined return type and server usage
src/adapters/_node/adapter.ts, test/node-adapters.test.ts, test/node-error-paths.test.ts, test/node-promises.test.ts
toNodeHandler returns the intersection of NodeHttp1Handler, NodeHttp2Handler, and AdapterMeta. Tests verify acceptance by both server constructors and remove NodeHttp1Handler casts.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • h3js/srvx#368: Changes the toNodeHandler() return type and removes casts to address the same linked issue.

Suggested reviewers: pi0x

Merge Risk: Minimal · up to e3b4f

This change lets the Node handler be passed to HTTP and HTTP/2 servers without casts, with no runtime behavior change. The one documented caveat about handlers round-tripped through the fetch adapter is accepted, so the change looks ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: toNodeHandler's return type becomes NodeHttp1Handler & NodeHttp2Handler, which matches the adapter.ts type change and the objectives (PR #376, issue #367). The fix(nod…
Linked Issues check Passed [#367] Issue #367 requires that the return type of toNodeHandler() allow direct passing to node:http, node:https, and node:http2 servers without a cast. At the reviewed head, `src/adapters/_no…
Out of Scope Changes check Passed All reported changes serve issue #367. The return-type change and the internal __nodeHandler assertion in src/adapters/_node/adapter.ts implement the requested type. Removing the `NodeHttp1Handler…
Full details: Title check

Explanation

The title names the main change: toNodeHandler's return type becomes NodeHttp1Handler & NodeHttp2Handler, which matches the adapter.ts type change and the objectives (PR #376, issue #367). The fix(node) prefix matches the node adapter scope. The test updates and the new createServer assignment test are supporting changes that the title does not need to cover.

Full details: Linked Issues check

Explanation

[#367] Issue #367 requires that the return type of toNodeHandler() allow direct passing to node:http, node:https, and node:http2 servers without a cast. At the reviewed head, src/adapters/_node/adapter.ts declares toNodeHandler(...) as returning NodeHttp1Handler & NodeHttp2Handler & AdapterMeta, which matches the issue's expected return type. The __nodeHandler cached-return path is cast to the same type. The convertedNodeHandler path returns without a cast. The summary reports that the as NodeHttp1Handler workarounds were removed from test/node-adapters.test.ts, test/node-error-paths.test.ts, and test/node-promises.test.ts, and that a new assignability test was added to test/node-adapters.test.ts. I read the source file only. I did not read the test diffs or run the TypeScript compiler, so the test-file changes rest on the PR summary. The issue's round-trip caveat is acknowledged in the PR description; it does not add a coding requirement.

Full details: Out of Scope Changes check

Explanation

All reported changes serve issue #367. The return-type change and the internal __nodeHandler assertion in src/adapters/_node/adapter.ts implement the requested type. Removing the NodeHttp1Handler casts and adding an assignability test in the three test files support the same objective. No runtime behavior change or unrelated edit is reported. The test-file hunks were not read directly, so this verdict relies on the PR summary for those files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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

A rabbit checks the handler’s type,
For HTTP/1 and HTTP/2 alike.
No cast is needed in the test,
The inferred type now meets the request.
Hop, hop, both servers accept it right!

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 43ab22d4-fd87-40ad-a4a3-7ea6233ba390
Commits

Reviewing files that changed from the base of the PR and between 14641b9 and e3b4f31.

Files selected for processing: 4

  • src/adapters/_node/adapter.ts
  • test/node-adapters.test.ts
  • test/node-error-paths.test.ts
  • test/node-promises.test.ts

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

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.

toNodeHandler() return type is not assignable to node:http / node:http2 servers

1 participant