Comfy-Org / Comfy-Org/ComfyUI_frontend

Optimize renderUploadSpinner: remove redundant ctx.save()/restore()

Open
#9,233 0 comments 0 reactions 1 assignee Claimed by @christian-byrne View on GitHub
area:nodes
Dominant language
TypeScript
Stars
2k
Forks
699
Avg merge
1d 7h
Merged PRs (30d)
490

Description

## Description
Remove the redundant `ctx.save()` and `ctx.restore()` calls in the `renderUploadSpinner` function, as the parent `drawFrontCanvas` (lines 4917/4929) already handles canvas state cleanup for each node.

## Context
- **File**: `src/renderer/extensions/vueNodes/widgets/composables/useImagePreviewWidget.ts`
- **Function**: `renderUploadSpinner` (lines 46-70)
- The function runs every frame during upload animation, making this optimization worthwhile
- The caller's per-node save/restore already handles cleanup, so we can set properties directly

## Suggested Change
Replace:
```typescript
ctx.save()
ctx.strokeStyle = LiteGraph.NODE_TEXT_COLOR
ctx.lineWidth = 3
ctx.lineCap = 'round'
// ... drawing code
ctx.restore()
```

With:
```typescript
ctx.strokeStyle = LiteGraph.NODE_TEXT_COLOR
ctx.lineWidth = 3
ctx.lineCap = 'round'
// ... drawing code
```

## References
- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9189
- Comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9189#discussion_r2856396569
- Requested by: @christian-byrne

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9233-Optimize-renderUploadSpinner-remove-redundant-ctx-save-restore-3136d73d365081e38208e38e57072de5) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.