{"version":3,"sources":["../../../../src/server/app-render/debug-channel-server.node.ts"],"sourcesContent":["/**\n * Node debug channel implementation.\n * Loaded by debug-channel-server.ts when __NEXT_USE_NODE_STREAMS is enabled.\n */\n\nimport { PassThrough, Writable, type Readable } from 'node:stream'\nimport type { DebugChannelServer } from './debug-channel-server.web'\n\nexport { createWebDebugChannel } from './debug-channel-server.web'\n\n/**\n * Node variant: identical to `DebugChannelPair` except the client-side readable\n * is narrowed to a Node `Readable`, so node call sites can consume it (e.g.\n * `new ReplayableNodeStream(...)`) without casting `AnyStream` down.\n */\nexport type NodeDebugChannelPair = {\n  serverSide: DebugChannelServer\n  clientSide: { readable: Readable }\n}\n\n/**\n * Creates a debug channel using Node.js streams.\n * Use with renderToNodeFlightStream (React's renderToPipeableStream),\n * which expects debugChannel to be a Node.js stream with a .write() method.\n */\nexport function createNodeDebugChannel(): NodeDebugChannelPair {\n  // The readable side is a PassThrough that the client reads from. The\n  // server-side write target is a separate, write-only Writable that forwards\n  // into it rather than the PassThrough itself: React's renderToPipeableStream\n  // detects `.read()` on the debug channel and would enter bidirectional mode,\n  // reading its own output back as commands.\n  //\n  // The forwarding must use `passthrough.write()` / `passthrough.end()`, not\n  // `passthrough.push()` / `passthrough.push(null)`. A PassThrough is a Duplex;\n  // pushing `null` ends only its readable half and leaves the writable half\n  // open (`writableEnded` stays false). If the readable is consumed via\n  // `Readable.toWeb()`, that web stream never closes while the PassThrough's\n  // writable half is still open — so the debug channel would never close on the\n  // client. Ending it via `passthrough.end()` closes both halves and the close\n  // propagates.\n  const passthrough = new PassThrough()\n\n  const writable = new Writable({\n    write(chunk, encoding, callback) {\n      passthrough.write(chunk, encoding, callback)\n    },\n    final(callback) {\n      passthrough.end(callback)\n    },\n  })\n\n  return {\n    serverSide: writable,\n    clientSide: { readable: passthrough },\n  }\n}\n"],"names":["PassThrough","Writable","createWebDebugChannel","createNodeDebugChannel","passthrough","writable","write","chunk","encoding","callback","final","end","serverSide","clientSide","readable"],"mappings":"AAAA;;;CAGC,GAED,SAASA,WAAW,EAAEC,QAAQ,QAAuB,cAAa;AAGlE,SAASC,qBAAqB,QAAQ,6BAA4B;AAYlE;;;;CAIC,GACD,OAAO,SAASC;IACd,qEAAqE;IACrE,4EAA4E;IAC5E,6EAA6E;IAC7E,6EAA6E;IAC7E,2CAA2C;IAC3C,EAAE;IACF,2EAA2E;IAC3E,8EAA8E;IAC9E,0EAA0E;IAC1E,sEAAsE;IACtE,2EAA2E;IAC3E,8EAA8E;IAC9E,6EAA6E;IAC7E,cAAc;IACd,MAAMC,cAAc,IAAIJ;IAExB,MAAMK,WAAW,IAAIJ,SAAS;QAC5BK,OAAMC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ;YAC7BL,YAAYE,KAAK,CAACC,OAAOC,UAAUC;QACrC;QACAC,OAAMD,QAAQ;YACZL,YAAYO,GAAG,CAACF;QAClB;IACF;IAEA,OAAO;QACLG,YAAYP;QACZQ,YAAY;YAAEC,UAAUV;QAAY;IACtC;AACF","ignoreList":[0]}