From 3a3e6a3c72038c29c840d0c9ed4cc61c231940da Mon Sep 17 00:00:00 2001 From: "Sota Iguchi (e-chan1007)" Date: Thu, 25 Jun 2026 23:11:25 +0900 Subject: [PATCH 1/2] fix: patch the createInlinedDataReadableStream function not to use the 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/shy-laws-wonder.md | 10 +++++ .../cli/build/open-next/createServerBundle.ts | 2 + .../flight-readable-stream-type.spec.ts | 25 ++++++++++++ .../plugins/flight-readable-stream-type.ts | 40 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 .changeset/shy-laws-wonder.md create mode 100644 packages/cloudflare/src/cli/build/patches/plugins/flight-readable-stream-type.spec.ts create mode 100644 packages/cloudflare/src/cli/build/patches/plugins/flight-readable-stream-type.ts diff --git a/.changeset/shy-laws-wonder.md b/.changeset/shy-laws-wonder.md new file mode 100644 index 000000000..a58919754 --- /dev/null +++ b/.changeset/shy-laws-wonder.md @@ -0,0 +1,10 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix: patch the createInlinedDataReadableStream function not to use the 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. + +(fixes #1225) diff --git a/packages/cloudflare/src/cli/build/open-next/createServerBundle.ts b/packages/cloudflare/src/cli/build/open-next/createServerBundle.ts index c556b6026..8107c79cc 100644 --- a/packages/cloudflare/src/cli/build/open-next/createServerBundle.ts +++ b/packages/cloudflare/src/cli/build/open-next/createServerBundle.ts @@ -27,6 +27,7 @@ import type { Plugin } from "esbuild"; import { getOpenNextConfig } from "../../../api/config.js"; import { normalizePath } from "../../utils/normalize-path.js"; +import { patchFlightReadableStreamType } from "../patches/plugins/flight-readable-stream-type.js"; import { patchResRevalidate } from "../patches/plugins/res-revalidate.js"; import { patchTurbopackRuntime } from "../patches/plugins/turbopack.js"; import { patchUseCacheIO } from "../patches/plugins/use-cache.js"; @@ -209,6 +210,7 @@ async function generateBundle( awsPatches.patchBackgroundRevalidation, awsPatches.patchNodeEnvironment, // Cloudflare specific patches + patchFlightReadableStreamType, patchResRevalidate, patchUseCacheIO, patchTurbopackRuntime, diff --git a/packages/cloudflare/src/cli/build/patches/plugins/flight-readable-stream-type.spec.ts b/packages/cloudflare/src/cli/build/patches/plugins/flight-readable-stream-type.spec.ts new file mode 100644 index 000000000..5cd551b6b --- /dev/null +++ b/packages/cloudflare/src/cli/build/patches/plugins/flight-readable-stream-type.spec.ts @@ -0,0 +1,25 @@ +import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js"; +import { describe, expect, test } from "vitest"; + +import { rule } from "./flight-readable-stream-type.js"; + +describe("patchFlightReadableStreamType", () => { + test("removes type property", () => { + const code = ` +function tl(e,t,r){ + let n = t ? '