-
Notifications
You must be signed in to change notification settings - Fork 601
Description
Creating a Hono app with c3
pnpm create cloudflare@latest --framework=hono --platform=pagesTrigger the following error at runtime when fetch_iterable_type_support is enabled:
✘ [ERROR] Uncaught TypeError: This ReadableStream did not return bytes.
Note that using --platform=workers does not trigger the error but only because the template are different.
The culprit is the jsxRenderer of Hono, the code is similar to:
import { Hono } from 'hono'
import { jsxRenderer } from 'hono/jsx-renderer'
const app = new Hono<{ Bindings: CloudflareBindings }>();
export const renderer = jsxRenderer(({ children }) => {
return (
<html>
<body>{children}</body>
</html>
)
})
app.use(renderer)
app.get('/', (c) => {
return c.render(<h1>Hello!</h1>)
})
export default appThe problematic code is (streaming code is disabled):
Where body is an HtmlEscapedString
A minimal repro would be:
export const raw = (value: unknown) => {
const escapedString = new String(value) as any;
escapedString.isEscaped = true
return escapedString
}
export default {
async fetch(request, env, ctx): Promise<Response> {
return new Response(raw('Hello World!'));
},
} satisfies ExportedHandler<Env>;From there I tried to run the following code on Node, Chrome, and Workers.
export const raw = (value) => {
const escapedString = new String(value);
escapedString.isEscaped = true;
return escapedString;
};
const response = new Response(raw('hello world'));
const text = await response.text();
console.log({ text });The Node and browser version output { text: 'hello world' } while the Workers version error with "TypeError: This ReadableStream did not return bytes." when fetch_iterable_type_support is enabled (it works when it is not enabled).
So it sounds like we have a problem in the implementation ?
I was also wondering if fetch_iterable_type_support should have any effect outside of nodejs_compat mode but I guess we could work on fixing the above issue first.
/cc @jasnell @danlapid @petebacondarwin @yusukebe
ref: internal chat thread