From 8b5e43d7f3488d6ee9e7d79994ad9b8c57dc462e Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Wed, 3 Dec 2025 20:34:56 -0500 Subject: [PATCH] fix: reset touch state when iPad Safari loses focus (#7134) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary When the browser loses focus (e.g., switching apps, showing the dock), touchend events may not fire, causing touchCount to remain non-zero. This blocks all subsequent single-finger interactions since processMouseDown returns early when touchCount > 0. Added visibilitychange and touchcancel event listeners to reset touch state when the page becomes hidden or touch is interrupted by the system. fix https://github.com/Comfy-Org/ComfyUI_frontend/issues/6721 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7134-fix-reset-touch-state-when-iPad-Safari-loses-focus-2be6d73d3650819abc7cf9c602909228) by [Unito](https://www.unito.io) --- src/extensions/core/simpleTouchSupport.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/extensions/core/simpleTouchSupport.ts b/src/extensions/core/simpleTouchSupport.ts index c129711ec8..67215f4719 100644 --- a/src/extensions/core/simpleTouchSupport.ts +++ b/src/extensions/core/simpleTouchSupport.ts @@ -1,6 +1,6 @@ import { LGraphCanvas, LiteGraph } from '@/lib/litegraph/src/litegraph' -import { app } from '../../scripts/app' +import { app } from '@/scripts/app' let touchZooming = false let touchCount = 0 @@ -82,6 +82,26 @@ app.registerExtension({ } ) + const resetTouchState = () => { + touchCount = 0 + touchZooming = false + touchTime = null + lastTouch = null + lastScale = null + touchDist = null + } + + // Reset touch state when page loses visibility (e.g., switching apps on iPad) + // This prevents touchCount from getting stuck when touchend events are missed + document.addEventListener('visibilitychange', () => { + if (document.hidden) { + resetTouchState() + } + }) + + // Also handle touchcancel which fires when touch is interrupted + app.canvasEl.parentElement?.addEventListener('touchcancel', resetTouchState) + app.canvasEl.parentElement?.addEventListener( 'touchmove', (e) => {