fix: remove type: "bytes" from ReadableStream for flight data#1293
Open
e-chan1007 wants to merge 2 commits into
Open
fix: remove type: "bytes" from ReadableStream for flight data#1293e-chan1007 wants to merge 2 commits into
e-chan1007 wants to merge 2 commits into
Conversation
…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 detectedLatest commit: e9bf437 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
add `kind: function_declaration` and specificity test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thecreateInlinedDataReadableStreamfunction, which reconstructs aReadableStreamusing thetype: "bytes"(BYOB) option.However,
workerdsplits theReadableStreamin 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
createInlinedDataReadableStreamfunction to remove thetype: "bytes"option, using the default stream mode without chunk splitting. While the underlying bug seems to be withinworkerditself, applying this patch serves as immediate workaround rather than waiting for an upstream fix in the runtime.Validation
pnpm code:checkspassedpnpm testpassed