chore(rsc): debug rsc-html-stream uncaught enqueue error#573
Conversation
|
I found a reproduction by imitating hono node server's stream https://stackblitz.com/edit/stackblitz-starters-hjmrwbfj?file=index.js import { injectRSCPayload } from 'rsc-html-stream/server';
async function main() {
let htmlStream = new ReadableStream({
async start(controller) {
controller.enqueue(
new TextEncoder().encode('<html><body>Hello World</body></html>')
);
controller.close();
},
});
let rscStream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode('[rsc]'));
controller.close();
},
});
htmlStream = htmlStream.pipeThrough(injectRSCPayload(rscStream));
const decoder = new TextDecoder();
const reader = htmlStream.getReader();
// asynchronously read and cancel
// https://github.com/honojs/node-server/blob/cb52c36d1d5d5b68416c807ce4b231c8bc549e29/src/utils.ts#L4-L42
reader.read().then((result) => {
console.log(result);
console.log({ decoded: decoder.decode(result.value) });
});
setTimeout(() => {
console.log('[cancel]');
reader.cancel('boom!').catch((e) => {
console.error('[cancel:error]', e);
});
}, 0);
}
main();$ node index.js
[cancel!]
[read:result]
{ value: undefined, done: true }
{ decoded: '' }
⚠️ uncaughtException ⚠️ TypeError [ERR_INVALID_STATE]: Invalid state: Unable to enqueue
at transformStreamDefaultControllerEnqueue (node:internal/webstreams/transformstream:284:8196)
at TransformStreamDefaultController.enqueue (node:internal/webstreams/transformstream:284:6374)
at flushBufferedChunks (file:///home/projects/stackblitz-starters-hjmrwbfj/node_modules/rsc-html-stream/server.js:35:18)
at Timeout.eval (file:///home/projects/stackblitz-starters-hjmrwbfj/node_modules/rsc-html-stream/server.js:58:9)
at <anonymous> (node:internal/timers:253:4719) {
code: 'ERR_INVALID_STATE'
} |
|
I went through many layers and we probably got to the bottom of it. devongovett/rsc-html-stream#10 This edge case doesn't happen on Actually |
Description
todo
rsc-html-streamalone