ajaxorg / ajaxorg/ace

ace.js: resetPressedKeys() called too many times

Aberta
#5,991 5 comentários 0 reações 0 responsáveis Ver no GitHub
bug p2
Linguagem predominante
JavaScript
Estrelas
27.1k
Forks
5.3k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

### Describe the bug

Hi,

I'm currently using ace.js from `https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js`, after upgrading from 1.43.2. This issue occurs in both versions.
A handler is defined on the window focus event (`addListener(window, "focus", resetPressedKeys);`, line 2025).
It can be called dozens of times on each ajax request, and ends up running indefinitely.

### Expected Behavior

No infinite (or too long?) loop on the resetPressedKeys() event handler.

### Current Behavior

Under certain conditions (an ajax request returning an error in my case), the `resetPressedKeys()` handler is called so many times that the page doesn't respond anymore.
In Firefox, no other event can be processed, and the page has to be reloaded.
Chrome is able to detect the issue, and prints this message in the console.
```
[Violation] 'focus' handler took 11151ms ace.js:2028
[Violation] 'focus' handler took 2496ms ace.js:2028
[Violation] 'focus' handler took 6311ms ace.js:2028
```
But it re-enters the same loop right after any event is triggered on the page.

Here's the stack trace of the first call to `resetPressedKeys()`.
```
resetPressedKeys (https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js#2029)
addListener (https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js#1841)
addCommandKeyListener (https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js#2025)
TextInput (https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js#2190)
Editor (https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js#14328)
edit (https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js#21996)
create (http://localhost:7090/#1561)
```
Excepted `resetPressedKeys()`, no other function in this stack is called during the loops.

### Reproduction Steps

1. Load `https://cdn.jsdelivr.net/npm/ace-builds@1.44.0/src-noconflict/ace.js` in a webpage.
2. Create an editor instance: `const editor = ace.edit(containerId, {/* options */});`
3. Execute a ajax request which returns an error (*).

### Possible Solution

Maybe I would suggest to attach the `resetPressedKeys()` handler to another event.

### Additional Information/Context

(*) Note: I'm not really sure about what actually triggers the issue, ie the third point in the reproduction steps.

### Ace Version / Browser / OS / Keyboard layout

ace.js 1.44.0, Firefox 152.0 and Chrome 150.0, Windows 11 with french keyboard layout.

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Start at addCommandKeyListener and resetPressedKeys in the generated ace.js stack around lines 2025-2029, then reproduce editor creation after an AJAX request returns an error in Firefox and Chrome. Trace why the focus handler is repeatedly invoked; done means resetPressedKeys no longer loops indefinitely and the page remains responsive.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript
Domínio
frontend
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Pouca atividade
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.