Skip to content

Commit d3a34f3

Browse files
committed
fix(review): resolve promptTitle race condition
The close event fired synchronously when rl.close() was called inside the question callback, causing resolve(null) from the close handler to settle the Promise before resolve(answer) ran — so typed titles were always discarded. Drop the close event handler and resolve entirely in the question callback. On Ctrl-C readline calls the callback with an empty string, which is coerced to null via `answer || null`.
1 parent 363252d commit d3a34f3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/review.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,12 @@ async function promptTitle(current: string | null): Promise<string | null> {
167167
(answer) => {
168168
rl.close();
169169
hideCursor();
170-
// If user pressed Ctrl-C, readline emits close event before question callback
171-
// We handle that via the 'close' event on rl
172-
resolve(answer);
170+
// On Ctrl-C, readline calls the question callback with an empty string.
171+
// Treat empty string as null (cancel / clear) — callers distinguish
172+
// "cancelled" from "set to empty" by receiving null either way.
173+
resolve(answer || null);
173174
},
174175
);
175-
// Handle Ctrl-C during input
176-
rl.on("close", () => {
177-
hideCursor();
178-
resolve(null);
179-
});
180176
});
181177
}
182178

0 commit comments

Comments
 (0)