Fix stdin buffer splitting bug in bridge

This commit is contained in:
Jared Miller 2026-01-27 17:54:31 -05:00
parent c8020154e7
commit dcd97a451f
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -128,11 +128,14 @@ function setContent(newContent: string) {
} }
// read json lines from stdin // read json lines from stdin
let buffer = "";
const decoder = new TextDecoder(); const decoder = new TextDecoder();
for await (const chunk of Bun.stdin.stream()) { for await (const chunk of Bun.stdin.stream()) {
const lines = decoder.decode(chunk).trim().split("\n"); buffer += decoder.decode(chunk);
const lines = buffer.split("\n");
buffer = lines.pop() ?? ""; // keep incomplete last line
for (const line of lines) { for (const line of lines) {
if (!line) continue; if (!line.trim()) continue;
try { try {
const msg = JSON.parse(line); const msg = JSON.parse(line);
switch (msg.type) { switch (msg.type) {