JS error uiPromise is not defined when adding hook to `editor_did_init_left_buttons`

I’m not sure if this is a bug or error.

To reproduce (anki 2.1.60):

from aqt import gui_hooks

def on_clicked(editor):
    print("clicked")


def test(buttons, editor):
    buttons.append(editor.addButton(None, "clicked", on_clicked))

gui_hooks.editor_did_init_left_buttons.append(test)

When opening the editor window,
Expected behavior: button appears in the left group of the editor toolbar and prints “clicked” in the console when clicked

Actual behavior: button is not there and JS error /_anki/legacyPageData?id=1945122782224:1 Uncaught ReferenceError: uiPromise is not defined is output to the console.

Note: this error does not occur when the hook is added to editor_did_init_buttons instead. I suspect this is because the generated js is different. The relevant source code is in /qt/aqt/editor.py Line 173 (I would link to it on GH but I’m not allowed to).

I would try to solve this issue and make a PR on my own but I 1. don’t know if it’s a bug or 2. how to go about solving it if it was.