Comfy-Org / Comfy-Org/ComfyUI_frontend

refactor: privatize ChangeTracker lifecycle methods and introduce state enum

Open
#11,257 0 comments 0 reactions 1 assignee Claimed by @jaeone94 View on GitHub
developer experience Public API
Dominant language
TypeScript
Stars
2k
Forks
702
Avg merge
1d 8h
Merged PRs (30d)
512

Description

## Follow-up Refactoring: ChangeTracker Internal API Hardening

**Requested by:** @jaeone94
**Related PR:** https://github.com/Comfy-Org/ComfyUI_frontend/pull/10816
**Source comment:** https://github.com/Comfy-Org/ComfyUI_frontend/pull/10816#discussion_r3083577294

---

### Background

PR #10816 introduced `deactivate()` and `prepareForSave()` as instance methods on `ChangeTracker`. While they are marked `@internal`, they remain publicly accessible on the class and may be auto-exposed to extensions via `comfyAPIPlugin`.

### Tasks

#### 1. Convert lifecycle methods to module-scoped functions

Move `deactivate()` and `prepareForSave()` out of the `ChangeTracker` class and into module-scoped functions in a private file (e.g., `src/scripts/changeTrackerLifecycle.ts`). These functions should accept the `ChangeTracker` instance as a parameter, so they are not accessible on the public class surface and cannot be auto-exposed to extensions.

#### 2. Introduce a state enum for ChangeTracker

Replace the current boolean flags (`_restoringState`, `isLoadingGraph`) with a proper state enum, e.g.:

```ts
type ChangeTrackerState = 'idle' | 'restoring' | 'loading'
```

This makes state transitions explicit and avoids ambiguous overlapping boolean combinations.

#### 3. Do both together

Since both tasks touch the ChangeTracker state model and the internal/public API boundary, they should be implemented together to avoid partial privatization and keep internal state access consistent.

---

### Motivation

- Prevents lifecycle methods from leaking into the extension API surface
- Makes state transitions explicit and easier to reason about
- Reduces risk of incorrect usage by external code

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-11257-refactor-privatize-ChangeTracker-lifecycle-methods-and-introduce-state-enum-3436d73d3650818184cefa4f636c0db4) 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.