Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions COMPATIBILITY_UPDATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ComfyUI-Selectors Compatibility Update - 2026

## Issues Fixed

### ✅ Outdated Import Paths
- **Issue**: JavaScript files used relative paths no longer valid in newer ComfyUI versions
- **Solution**: Updated all paths from `../../scripts/app.js` to `../../../scripts/app.js`
- **Files modified**:
- `web/seed_history_ui.js`
- `web/width_height_swap.js`
- `web/extensions/dimension_selectors.js`

### ✅ Deprecated ctx.roundRect()
- **Issue**: `ctx.roundRect()` not supported in newer Canvas API versions
- **Solution**: Replaced with compatible implementation using `arcTo()` and `lineTo()`
- **Files modified**: `web/width_height_swap.js`

### ✅ Code Duplication
- **Issue**: Two similar dimension selector files causing conflicts
- **Solution**: Removed duplicate file `/web/extensions/dimension_selectors.js`
- **File kept**: `/web/js/dimension_selectors.js`

### ✅ Optimized Event Handling
- **Issue**: Heavy use of `setTimeout` and `setInterval` causing performance issues
- **Solution**:
- Replaced `setTimeout` with `requestAnimationFrame` for init
- Added `MutationObserver` for efficient value monitoring
- Reduced polling frequency from 1000ms to 2000ms as fallback
- Improved resource cleanup
- **Files modified**: `web/seed_history_ui.js`

## Verified Compatibility

These updates make the node compatible with:
- ComfyUI v0.3.0+
- Node.js v18+
- Modern browsers with ES6+ support

## Future Notes

1. **Testing**: Recommended to test nodes with latest ComfyUI version
2. **Monitoring**: Check JavaScript console for any new warnings
3. **Maintenance**: Consider periodic updates every 6-12 months

## Test Commands

```bash
# Restart ComfyUI after update
python main.py --listen 0.0.0.0

# Check console for JavaScript errors
# Open: http://localhost:8188 and verify comfyassets/ nodes
```

## Backup

A backup of the original state was created before the update for potential rollback.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "../../scripts/app.js";
import { app } from "../../../scripts/app.js";

console.log("ComfyUI Selectors extension loading...");

Expand Down
152 changes: 0 additions & 152 deletions web/extensions/dimension_selectors.js

This file was deleted.

48 changes: 35 additions & 13 deletions web/seed_history_ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ComfyUI_Selectors - Seed History with Tracking UI
import { app } from "../../scripts/app.js";
import { app } from "../../../scripts/app.js";

app.registerExtension({
name: "comfyassets.SeedHistory",
Expand Down Expand Up @@ -69,10 +69,10 @@ app.registerExtension({
};

// Hook into seed widget callbacks to track all changes
// Use setTimeout to ensure widgets are fully initialized
setTimeout(() => {
// Use requestAnimationFrame for better performance than setTimeout
requestAnimationFrame(() => {
this.setupSeedWidgetCallbacks();
}, 100);
});

// Also hook directly into widget value changes using LiteGraph
const originalOnWidgetChange = this.onWidgetChange;
Expand Down Expand Up @@ -111,14 +111,19 @@ app.registerExtension({
}
};

// Cleanup interval on node removal
// Cleanup interval and observer on node removal
const originalOnRemoved = this.onRemoved;
this.onRemoved = function () {
if (this.seedValueWatcher) {
clearInterval(this.seedValueWatcher);
this.seedValueWatcher = null;
}

if (this.seedValueObserver) {
this.seedValueObserver.disconnect();
this.seedValueObserver = null;
}

// Clean up deduplication tracking
if (this.lastAddedSeed) {
this.lastAddedSeed = null;
Expand Down Expand Up @@ -157,14 +162,31 @@ app.registerExtension({

// Note: Simplified to only use value monitoring and onWidgetChange to prevent multiple triggers

// Monitor for value changes that might not trigger callback
this.seedValueWatcher = setInterval(() => {
if (seedWidget.value !== this.lastSeedValue) {
console.log(`[SeedHistory] Detected seed value change: ${this.lastSeedValue} -> ${seedWidget.value}`);
this.lastSeedValue = seedWidget.value;
this.addSeedToHistory(seedWidget.value);
}
}, 1000);
// Monitor for value changes using MutationObserver for better performance
if (seedWidget.element) {
this.seedValueObserver = new MutationObserver(() => {
if (seedWidget.value !== this.lastSeedValue) {
console.log(`[SeedHistory] Detected seed value change: ${this.lastSeedValue} -> ${seedWidget.value}`);
this.lastSeedValue = seedWidget.value;
this.addSeedToHistory(seedWidget.value);
}
});

this.seedValueObserver.observe(seedWidget.element, {
attributes: true,
attributeFilter: ['value'],
subtree: true
});
} else {
// Fallback: use minimal polling if element not available
this.seedValueWatcher = setInterval(() => {
if (seedWidget.value !== this.lastSeedValue) {
console.log(`[SeedHistory] Detected seed value change: ${this.lastSeedValue} -> ${seedWidget.value}`);
this.lastSeedValue = seedWidget.value;
this.addSeedToHistory(seedWidget.value);
}
}, 2000); // Reduced frequency
}

// Note: Removed custom beforeQueued implementation to prevent duplicate increment/decrement operations
// ComfyUI handles increment/decrement/randomize internally, we just monitor the value changes
Expand Down
15 changes: 13 additions & 2 deletions web/width_height_swap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ComfyUI_Selectors - Width Height Node with Swap Button
import { app } from "../../scripts/app.js";
import { app } from "../../../scripts/app.js";

app.registerExtension({
name: "comfyassets.WidthHeightSwap",
Expand Down Expand Up @@ -97,7 +97,18 @@ app.registerExtension({
// Button background
ctx.fillStyle = "rgba(100,100,100,0.8)";
ctx.beginPath();
ctx.roundRect(swapButtonX, swapButtonY, swapButtonSize, swapButtonSize, 2);
// Use standard arc and lineTo instead of roundRect for compatibility
const radius = 2;
ctx.moveTo(swapButtonX + radius, swapButtonY);
ctx.lineTo(swapButtonX + swapButtonSize - radius, swapButtonY);
ctx.arcTo(swapButtonX + swapButtonSize, swapButtonY, swapButtonX + swapButtonSize, swapButtonY + radius, radius);
ctx.lineTo(swapButtonX + swapButtonSize, swapButtonY + swapButtonSize - radius);
ctx.arcTo(swapButtonX + swapButtonSize, swapButtonY + swapButtonSize, swapButtonX + swapButtonSize - radius, swapButtonY + swapButtonSize, radius);
ctx.lineTo(swapButtonX + radius, swapButtonY + swapButtonSize);
ctx.arcTo(swapButtonX, swapButtonY + swapButtonSize, swapButtonX, swapButtonY + swapButtonSize - radius, radius);
ctx.lineTo(swapButtonX, swapButtonY + radius);
ctx.arcTo(swapButtonX, swapButtonY, swapButtonX + radius, swapButtonY, radius);
ctx.closePath();
ctx.fill();

// Button border
Expand Down