#5991·ace

ace.js: resetPressedKeys() called too many times

Author: feuzeuCreated Jul 12, 2026Updated Aug 12, 2026
Labelsp2bug

Describe the bug

Hi,

I'm currently using ace.js from https://cdn.jsdelivr.net/npm/[email protected]/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/[email protected]/src-noconflict/ace.js#2029)
addListener (https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict/ace.js#1841)
addCommandKeyListener (https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict/ace.js#2025)
TextInput (https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict/ace.js#2190)
Editor (https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict/ace.js#14328)
edit (https://cdn.jsdelivr.net/npm/[email protected]/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/[email protected]/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.