Skip to content

React 18: "The stream is not in a state that permits close" in renderToReadableStream #22772

Closed
@jplhomer

Description

@jplhomer

When using renderToReadableStream for e.g. Cloudflare Workers runtimes, I'm noticing this error on the server:

TypeError: The stream is not in a state that permits close
    at ReadableStreamDefaultController.close (/Users/joshlarson/src/github.com/jplhomer/vite-streaming-ssr-demo/node_modules/web-streams-polyfill/src/lib/readable-stream/default-controller.ts:72:13)
    at Mc (/Users/joshlarson/src/github.com/jplhomer/vite-streaming-ssr-demo/dist/worker/worker.js:3636:145)
    at Bc (/Users/joshlarson/src/github.com/jplhomer/vite-streaming-ssr-demo/dist/worker/worker.js:3457:33)
    at ping (/Users/joshlarson/src/github.com/jplhomer/vite-streaming-ssr-demo/dist/worker/worker.js:3128:24)
GET / 200 OK (2091.13ms)

I'm assuming this results in the following malformed chunk being sent to the stream:

<div hidden id="<div hidden id="S:1">

Which results in the client failing:

Uncaught TypeError: Cannot read properties of null (reading 'parentNode')
    at $RS (127.0.0.1/:11)
    at 127.0.0.1/:11

I put together a reproduction here, powered by Miniflare for the Workers runtime: https://github.com/jplhomer/vite-streaming-ssr-demo

Possible issues

Metadata

Metadata

Assignees

Labels

React 18Bug reports, questions, and general feedback about React 18Type: Discussion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions