From bd916096ac30e04cfdf9df4b4935e7fb2e22ca41 Mon Sep 17 00:00:00 2001 From: Jin Yi Date: Thu, 29 Jan 2026 13:19:51 +0900 Subject: [PATCH] fix: add null check in getCanvasCenter to prevent crash on asset insert (#8399) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Adds null check in `getCanvasCenter()` to prevent crash when inserting asset as node before canvas is fully initialized. ## Changes - **What**: Added optional chaining for `app.canvas?.ds?.visible_area` with fallback to `[0, 0]` ## Review Focus - Simple defensive fix - returns origin position if canvas not ready 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8399-fix-add-null-check-in-getCanvasCenter-to-prevent-crash-on-asset-insert-2f76d73d365081e88c08ef40ea9e7b78) by [Unito](https://www.unito.io) --- 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 f071a2356..268d7a0a7 100644 --- a/src/services/litegraphService.ts +++ b/src/services/litegraphService.ts @@ -883,7 +883,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] }