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

[Bug]: Process exits when awaiting for keypress in some situations #3055

Closed
2 tasks done
frandiox opened this issue Nov 2, 2023 · 0 comments · Fixed by #3092
Closed
2 tasks done

[Bug]: Process exits when awaiting for keypress in some situations #3055

frandiox opened this issue Nov 2, 2023 · 0 comments · Fixed by #3092
Assignees
Labels
Area: @shopify/cli-kit @shopify/cli-kit package issues Type: Bug Something isn't working

Comments

@frandiox
Copy link
Contributor

frandiox commented Nov 2, 2023

Please confirm that you have:

  • Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

Hydrogen custom storefront

Expected behavior

await keypress() doesn't exit the process.

Actual behavior

In some situations, calling await keypress() simply ends the process in cli-kit >=3.50.0
It used to work in 3.49.7

Verbose output

See below

Reproduction steps

We are experiencing this in Hydrogen CLI with the command npm create @shopify/[email protected]. Choose "Login with Shopify" and it will internally call keypress, then exit immediately

I've trimmed this down to a combination of renderTextPrompt (or any rendering that accepts a key) followed by keypress:

import Command from '@shopify/cli-kit/node/base-command';
import {keypress, renderTextPrompt} from '@shopify/cli-kit/node/ui';

export default class Test extends Command {
  async run(): Promise<void> {
    console.log('1 start\n');
    await renderTextPrompt({message: 'Enter anything', allowEmpty: true});
    console.log('2 keypress');
    await keypress();
    console.log('3 end -- THIS SHOULD BE LOGGED');
  }
}

I believe the reason is that, somehow, Node's event loop becomes empty while awaiting for the keypress and it just exits.
If we artificially add something to the event loop, it works again:

    console.log('1 start\n');
    await renderTextPrompt({message: 'Enter anything', allowEmpty: true});
    console.log('2 keypress');

    const dummyTimeout = setTimeout(() => {}, 999999);
    await keypress();
    clearTimeout(dummyTimeout);

    console.log('3 end -- THIS SHOULD BE LOGGED');

Operating System

Mac OS Sonoma 14.0

Shopify CLI version (check your project's package.json if you're not sure)

3.50.1

Shell

zsh

Node version (run node -v if you're not sure)

v18.2.0

What language and version are you using in your application?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: @shopify/cli-kit @shopify/cli-kit package issues Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants