fix: add null check in getCanvasCenter to prevent crash on asset insert (#8399)

## 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 <noreply@anthropic.com>

┆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)
This commit is contained in:
Jin Yi
2026-01-29 13:19:51 +09:00
committed by GitHub
parent 9be853f6b5
commit bd916096ac

View File

@@ -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]
}