Skip to content

fix: remove type: "bytes" from ReadableStream for flight data#1293

Open
e-chan1007 wants to merge 2 commits into
opennextjs:mainfrom
e-chan1007:fix/flight-readable-stream-type
Open

fix: remove type: "bytes" from ReadableStream for flight data#1293
e-chan1007 wants to merge 2 commits into
opennextjs:mainfrom
e-chan1007:fix/flight-readable-stream-type

Conversation

@e-chan1007

@e-chan1007 e-chan1007 commented Jun 25, 2026

Copy link
Copy Markdown

Summary

This PR fixes the "Connection closed" error caused by corrupted RSC flight data streams on Cloudflare Workers.

Next.js generates inline <script> tags for embedding flight data in the createInlinedDataReadableStream function, which reconstructs a ReadableStream using the type: "bytes" (BYOB) option.

However, workerd splits the ReadableStream in BYOB mode into 4KB chunks and this can occasionally cause the data chunks to be read in the wrong order. When using nested or parallel <Suspense>, this behavior results in the flight data generated by multiple <Suspense> components getting mixed up. This corruption of the <script> tag payload triggers the "Connection closed" hydration error (as detailed in #1225 (comment)).

To resolve this issue, I implemented the patch for the createInlinedDataReadableStream function to remove the type: "bytes" option, using the default stream mode without chunk splitting. While the underlying bug seems to be within workerd itself, applying this patch serves as immediate workaround rather than waiting for an upstream fix in the runtime.

Validation

  • pnpm code:checks passed
  • pnpm test passed

Open in Devin Review

…e type: "bytes" option in ReadableStream constructor

workerd seems not to correctly support the type: "bytes" option in ReadableStream constructor, that breaks inlined flight data streaming over 4kB.
By removing the type: "bytes" option, the inlined flight data will not be split into multiple chunks, and the streaming will work correctly.
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e9bf437

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Open in Devin Review

add `kind: function_declaration` and specificity test
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