Skip to content

fix(vite): forward duplex fetch option in dispatcher#3561

Merged
pi0 merged 1 commit into
nitrojs:v3from
phryneas:pr/forward-init-duplex
Sep 2, 2025
Merged

fix(vite): forward duplex fetch option in dispatcher#3561
pi0 merged 1 commit into
nitrojs:v3from
phryneas:pr/forward-init-duplex

Conversation

@phryneas
Copy link
Copy Markdown
Contributor

@phryneas phryneas commented Sep 2, 2025

🔗 Linked issue

No issue found.

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

I encountered this when returning an AsyncIterable instance as the body of a Response in a TanStack Start api route handler using the nitro/vite plugin from nitro-nightly@3.0.0-20250902-103829-4daac97b.

That resulted in an unhandled error:

TypeError: RequestInit: duplex option is required when sending a body.
    at new Request (node:internal/deps/undici/undici:9813:19)
    ... 8 lines matching cause stack trace ...
    at next (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1740:18) {
  cause: TypeError: RequestInit: duplex option is required when sending a body.
      at new Request (node:internal/deps/undici/undici:9813:19)
      at globalThis.fetch (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:19:15)
      at globalThis.fetch (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/chunks/_/server.mjs:18205:16)
      at Object.handler (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:4975:10)
      at file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1871:35
      at callMiddleware (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1733:43)
      at next (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1740:18)
      at file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1711:50
      at callMiddleware (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1743:15)
      at next (file:///Users/tronic/tmp/apollo-next/integration-test/tanstack-start/.output/server/index.mjs:1740:18),
  status: 500,
  statusText: undefined,
  headers: undefined,
  data: undefined,
  body: undefined,
  unhandled: true
}

It seems that when the body of a fetch request is a ReadableStream, the duplex option must be set.

I tested this locally by making the same change manually to the .output/server/chunks/_/server.mjs file, and that resolved the issue.

I also have this on Vercel. You can try this API call without this PR and see it fail:

curl 'https://apolloclient-integration-tanstack-start-q2iw66ycl.vercel.app/api/graphql' \
  -X POST \
  -H 'Accept: application/graphql-response+json,application/json;q=0.9' \
  --data-raw '{"operationName":"dynamicProducts","variables":{},"extensions":{"clientLibrary":{"name":"@apollo/client","version":"4.0.0"}},"query":"query dynamicProducts($someArgument: String) {\n  products(someArgument: $someArgument) {\n    id\n    title\n    __typename\n  }\n  env\n}"}'

This is the same deployment after apollographql/apollo-client-integrations@1a9930f, which patches the changes from this PR:

curl 'https://apolloclient-integration-tanstack-start-lqr4wphz3.vercel.app/api/graphql' \
  -X POST \
  -H 'Accept: application/graphql-response+json,application/json;q=0.9' \
  --data-raw '{"operationName":"dynamicProducts","variables":{},"extensions":{"clientLibrary":{"name":"@apollo/client","version":"4.0.0"}},"query":"query dynamicProducts($someArgument: String) {\n  products(someArgument: $someArgument) {\n    id\n    title\n    __typename\n  }\n  env\n}"}'

📝 Checklist

  • I have linked an issue or discussion. (no existing issue)
  • I have updated the documentation accordingly. (no docs changes needed)

@phryneas phryneas requested a review from pi0 as a code owner September 2, 2025 13:27
@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 2, 2025

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

A member of the Team first needs to authorize it.

@phryneas phryneas changed the title forward duplex RequestInit option in dispatcher fix: forward duplex RequestInit option in dispatcher Sep 2, 2025
@pi0 pi0 changed the title fix: forward duplex RequestInit option in dispatcher fix(vite): forward duplex fetch option in dispatcher Sep 2, 2025
@pi0 pi0 merged commit 7e25f69 into nitrojs:v3 Sep 2, 2025
4 of 5 checks passed
@phryneas phryneas deleted the pr/forward-init-duplex branch September 2, 2025 18:30
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