gitbutlerapp/gitbutler · warning

Error triggering button click via hotkey:

Error message

Error triggering button click via hotkey:

What it means

The focus manager maps hotkeys to registered focusable buttons; on a match it calls element.click() synchronously inside try/catch. HTMLElement.click() itself essentially never throws — an exception here means the button's own click handler (or a synchronous listener on it) threw during dispatch. The catch warns, and the hotkey is still reported handled.

Source

Thrown at packages/ui/src/lib/focus/focusManager.ts:144

		// Find all buttons with hotkeys
		const entries = Array.from(this.nodeMap.entries());
		for (const [element, node] of entries) {
			if (node.options.button && node.options.hotkey) {
				// Parse the hotkey definition
				const parsed = parseHotkey(node.options.hotkey);
				if (!parsed) continue;

				// Check if the event matches the hotkey
				if (matchesHotkey(event, parsed)) {
					event.preventDefault();
					event.stopPropagation();

					// Trigger click on the button
					try {
						element.click();
					} catch (error) {
						console.warn("Error triggering button click via hotkey:", error);
					}
					return true;
				}
			}
		}
		return false;
	}

	// ============================================
	// Public API
	// ============================================

	listen() {
		return mergeUnlisten(
			on(document, "click", this.handleMouse, { capture: true }),
			on(document, "keydown", this.handleKeys),
		);
	}

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Click the same button with the mouse to reproduce — the real stack belongs to the handler, not focusManager
  2. Fix the throwing click handler; the warn here is a symptom
  3. Unregister hotkey nodes on unmount so stale elements are never clicked
  4. Make async handler work catch its own rejections so nothing escapes synchronously
Defensive patterns

Strategy: try-catch

Validate before calling

// Only click live, connected buttons
if (!(element instanceof HTMLElement) || !element.isConnected) continue;

Type guard

function isLiveButton(el: unknown): el is HTMLButtonElement {
	return el instanceof HTMLButtonElement && el.isConnected;
}

Try / catch

try {
	element.click();
} catch (error) {
	console.warn("Error triggering button click via hotkey:", error);
}
return true;

Prevention

When it happens

Trigger: Pressing a registered hotkey whose bound button's click handler throws — handler code with a bug, a listener on a detached element, or stale registry entries after DOM updates (packages/ui/src/lib/focus/focusManager.ts:144).

Common situations: A button handler failing only on the hotkey path (different event shape); focus registry entries not unregistered on unmount; third-party listeners throwing.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/a7ba763dbec602c9. Report an issue: GitHub.