nodejs / nodejs/node

Odd behavior with asynchronous console I/O in REPL

Ouverte
#43,074 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

confirmed-bug repl
Langage dominant
JavaScript
Étoiles
122k
Forks
37.3k
Merge moyen
4 j 2 h
PR mergées (30 j)
283

Description

Version

v16.15.0

Platform

Microsoft Windows NT 10.0.19044.0 x64

Subsystem

No response

What steps will reproduce the bug?
  1. Open the REPL.
  2. Run setTimeout(() => console.log('h'), 1000) and wait for the timer to expire. The letter h will print where the cursor was, and push the cursor down to the line after the prompt.
  3. Type another letter which results in autofill, such as g. This already looks somewhat broken, with the letter appearing a few columns to the left of the cursor.
  4. Hit tab to autofill. This is even more broken, as autofill picks up from the cursor rather than from the first letter.
  5. Hit backspace and watch the word magically fix itself, with a new prompt in the same line as the cursor.
How often does it reproduce? Is there a required condition?

It always occurs when console.log is called asynchronously after the prompt is rendered. process.stdout.write also has somewhat odd behavior, but is noticeably less broken than console.log, possibly because of the lack of a newline character on the end.

What is the expected behavior?

It should be consistent with Promise.reject:

> Promise.reject('h')
Promise {
  <rejected> 'h',
  [Symbol(async_id_symbol)]: 96,
  [Symbol(trigger_async_id_symbol)]: 5,
  [Symbol(destroyed)]: { destroyed: false }
}
> Uncaught 'h'
>

Note that, although this does print Uncaught 'h' after the prompt, it then prints a new prompt immediately. With setTimeout and console.log, the new prompt isn't printed until backspace is pressed.

What do you see instead?

After step 3:
image
After step 4:
image
After step 5:
image

Additional information

Although I discovered this in v16.15.0, it also appears to happen in v14.19.2, v17.9.0, and v18.1.0.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Reproduisez le problème dans le REPL Node.js en utilisant setTimeout avec console.log, puis suivez les E/S asynchrones de la console du REPL et la gestion de l’invite. La tâche est terminée lorsque la sortie asynchrone laisse une invite cohérente et préserve le comportement de la saisie, de l’autocomplétion et de la touche Retour arrière comme dans l’exemple Promise.reject.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
cli
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.