Description
Describe the bug
When showing promtps multiple times, if one of the prompt inputs is validated using async actions, keypresses on other prompts may be missed. Happens only on Windows.
To Reproduce
Steps to reproduce the behavior:
const fetch = require('node-fetch'); // use v2 that still supports CommonJS modules
const prompts = require('prompts');
const promptConfigs = [{
message: 'Prompt 1',
validate: async () => {
await fetch('https://jsonplaceholder.typicode.com/posts');
return true;
}
}, {
message: 'Prompt 2'
}, {
message: 'Prompt 3'
}];
async function main() {
for (const c of promptConfigs) {
await prompts({
type: 'text',
...c
});
}
}
main();
Actual behavior
On node 16.20.2: on "Prompt 3" no keypress events are triggered untill Enter key is pressed - then the input can be entered as usual; if you remove fetch
call from validate
callback then everything will work perfectly.
On node 20.6.1: on "Prompt 3", on the first key press, no keypress event is triggered. The second and all next keypresses will be handled correctly.
Also, I have a project which I cannot post here, there I have the behavior described for node 16.20.2 even when it is run on 20.6.1.
Expected behavior
All key presses should be handled correctly.
System
- OS: Windows 10 Pro 22H2
- Terminal: cmd, Poweshell
- Node version: 16.20.2, 20.6.1
Additional context
It may be Node issue. I encountered similar issues in this repo, still there wasn't anything about validate callback there.