From 54e8775acb11e5e0df870c13d73834f9687478dd Mon Sep 17 00:00:00 2001 From: Comfy Org PR Bot Date: Thu, 29 Jan 2026 13:48:47 +0900 Subject: [PATCH] [backport core/1.38] fix: add null check in getCanvasCenter to prevent crash on asset insert (#8403) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport of #8399 to `core/1.38` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8403-backport-core-1-38-fix-add-null-check-in-getCanvasCenter-to-prevent-crash-on-asset-ins-2f76d73d365081b6af21e13162afafc5) by [Unito](https://www.unito.io) Co-authored-by: Jin Yi --- src/services/litegraphService.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/litegraphService.ts b/src/services/litegraphService.ts index 18d281973..d459f3de5 100644 --- a/src/services/litegraphService.ts +++ b/src/services/litegraphService.ts @@ -876,7 +876,11 @@ export const useLitegraphService = () => { function getCanvasCenter(): Point { const dpi = Math.max(window.devicePixelRatio ?? 1, 1) - const [x, y, w, h] = app.canvas.ds.visible_area + const visibleArea = app.canvas?.ds?.visible_area + if (!visibleArea) { + return [0, 0] + } + const [x, y, w, h] = visibleArea return [x + w / dpi / 2, y + h / dpi / 2] }