Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async when causes unexpected behavior #1062

Open
baileyherbert opened this issue Nov 2, 2021 · 1 comment
Open

Async when causes unexpected behavior #1062

baileyherbert opened this issue Nov 2, 2021 · 1 comment

Comments

@baileyherbert
Copy link

baileyherbert commented Nov 2, 2021

Platforms: Windows 10, 11
Node versions: 14, 16

When a prompt has an async when which returns false after some time, the next prompt will not start registering input until the enter key is pressed, and the question is duplicated.

  • If the async when resolves immediately, or within a single tick (e.g. setTimeout with 1ms) then the issue does not occur.
  • If when is set to false directly, the issue also does not occur.

Reproduced on both the latest version 8.2.0 and the much older 6.5.0.

Here's an example:

repro

And the code used:

const inquirer = require('inquirer');

(async function () {
	await inquirer.prompt({
		name: 'cancelled',
		type: 'input',
		message: 'Enter some text (hidden)',
		when: async () => {
			// Set this timeout to 0, 1 or remove it and the issue goes away??
			await new Promise(r => setTimeout(r, 50));
			return false
		}
	});

	console.log(await inquirer.prompt({
		name: 'input1',
		type: 'input',
		message: 'Enter some text (#1)'
	}));

	console.log(await inquirer.prompt({
		name: 'input2',
		type: 'input',
		message: 'Enter some text (#2)'
	}));
})();
@nofear-js
Copy link

The same effect occurs with async validate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants