Skip to content

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jun 8, 2025

Fetch API signuture is (req, init?); however, no other runtimes agree on this, yet called it .fetch...

  • Bun: fetch(request, server)
  • Deno: fetch(request, info)
  • Cloudflare: fetch(request, env, ctx)

It might be safer to have h3.fetch strictly only accept a single (request). This also helps avoid wrongly added overhead if one does export default app.fetch (which causes recreating Request with a second irrelevant arg considered RequestInit)

Downside, it takes away the easy DX of doing app.fetch("url", { headers: {} }) => app._fetch("url", { headers: {} }) :( (we could call it app.request ~> #1176)

@pi0
Copy link
Member Author

pi0 commented Jun 8, 2025

Canceling the idea for now. Not worth killing DX only to prevent shooting in the foot implied by runtimes.

@pi0 pi0 closed this Jun 8, 2025
@pi0 pi0 reopened this Jul 30, 2025
@pi0
Copy link
Member Author

pi0 commented Jul 30, 2025

Reopening as it can be also a fatal issue for integrations, e.g if second arg uses an overlapping key like cache it can break fetch implementations.

@pi0 pi0 changed the title refactor: only accept request for H3.fetch refactor!: only accept request for H3.fetch Jul 30, 2025
Copy link

cloudflare-workers-and-pages bot commented Jul 30, 2025

Deploying h3dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: ba19814
Status: ✅  Deploy successful!
Preview URL: https://dd554023.h3dev.pages.dev
Branch Preview URL: https://refactor-safe-fetch.h3dev.pages.dev

View logs

Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/handler.ts 42.85% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@pi0 pi0 changed the title refactor!: only accept request for H3.fetch refactor!: only accept request for H3 and EventHandlerWithFetch fetch Jul 30, 2025
@pi0 pi0 changed the title refactor!: only accept request for H3 and EventHandlerWithFetch fetch refactor!: only accept req for H3 and EventHandlerWithFetch fetch Jul 30, 2025
@pi0 pi0 merged commit 877efd5 into main Jul 30, 2025
4 of 5 checks passed
@pi0 pi0 deleted the refactor/safe-fetch branch July 30, 2025 11:54
@pi0 pi0 mentioned this pull request Jul 30, 2025
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