Skip to content

Conversation

Myestery
Copy link
Collaborator

@Myestery Myestery commented Oct 8, 2025

This pull request introduces a new extension API for context menu customization, allowing extensions to contribute items to both canvas and node right-click menus. It adds two collection methods to the ComfyApp class to aggregate these menu items from all registered extensions, and updates the extension interface accordingly. Comprehensive unit tests are included to verify the correct aggregation behavior and error handling.

Extension API for Context Menus:

  • Added optional getCanvasMenuItems and getNodeMenuItems methods to the ComfyExtension interface, enabling extensions to provide context menu items for canvas and node right-click menus (src/types/comfy.ts).

  • Updated type imports to support the new API, including IContextMenuValue, LGraphCanvas, and LGraphNode (src/types/comfy.ts, src/scripts/app.ts). [1] [2]

Core Implementation:

  • Implemented collectCanvasMenuItems and collectNodeMenuItems methods in the ComfyApp class to gather menu items from all extensions, with robust error handling and logging for extension failures (src/scripts/app.ts).

Testing:

  • Added a comprehensive test suite for the new context menu extension API, covering aggregation logic, error handling, and integration scenarios (tests-ui/tests/extensions/contextMenuExtension.test.ts).

This is PR 1 of the 3 PRs in the Contextmenu standardizations.
-#5992
-#5993

Copy link

github-actions bot commented Oct 8, 2025

🎭 Playwright Test Results

⚠️ Tests passed with flaky tests

⏰ Completed at: 10/10/2025, 01:15:48 AM UTC

📈 Summary

  • Total Tests: 490
  • Passed: 458 ✅
  • Failed: 0
  • Flaky: 2 ⚠️
  • Skipped: 30 ⏭️

📊 Test Reports by Browser

  • chromium: View Report • ✅ 449 / ❌ 0 / ⚠️ 2 / ⏭️ 30
  • chromium-2x: View Report • ✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0
  • chromium-0.5x: View Report • ✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0
  • mobile-chrome: View Report • ✅ 6 / ❌ 0 / ⚠️ 0 / ⏭️ 0

🎉 Click on the links above to view detailed test results for each browser configuration.

Copy link

github-actions bot commented Oct 8, 2025

🎨 Storybook Build Status

Build completed successfully!

⏰ Completed at: 10/10/2025, 12:59:22 AM UTC

🔗 Links


🎉 Your Storybook is ready for review!

Introduces a new extension API that allows extensions to provide context menu items directly, without monkey-patching. This provides a clean, type-safe way for extensions to add menu items.

**New API methods:**
- `getCanvasMenuItems(canvas)`: Add items to canvas right-click menus
- `getNodeMenuItems(node)`: Add items to node right-click menus

**Implementation:**
- Added TypeScript interfaces in `src/types/comfy.ts`
- Added collection methods in `ComfyApp` class
- Comprehensive test coverage for the new API
@Myestery Myestery force-pushed the contextmenu-for-extensions branch from 4d23f7b to 3bc9bcc Compare October 9, 2025 00:54
Myestery added a commit that referenced this pull request Oct 9, 2025
…extensions

Adds a compatibility layer that detects and supports legacy extensions using the monkey-patching pattern, while warning developers about the deprecated approach.

**Features:**
- Automatic detection of monkey-patched context menu methods
- Console warnings with extension name for deprecated patterns
- Extraction and integration of legacy menu items
- Extension tracking during setup for accurate warnings

**Files:**
- `src/lib/litegraph/src/contextMenuCompat.ts`: Core compatibility logic
- `src/services/extensionService.ts`: Extension name tracking
- `src/composables/useContextMenuTranslation.ts`: Integration layer
- Comprehensive test coverage

Depends on PR #5977 (context menu extension API)
Myestery added a commit that referenced this pull request Oct 9, 2025
Migrates core extensions from monkey-patching to the new context menu extension API, demonstrating the migration path for extension developers.

**Migrated extensions:**
- `groupOptions.ts`: Group management context menu items
- `nodeTemplates.ts`: Template save/load context menu items

**Legacy compatibility test:**
- `groupNode.ts`: Kept with monkey-patching as compatibility test case
- Includes documentation explaining the old vs new approach

**Benefits:**
- Type-safe menu item registration
- No prototype pollution
- Easier to test and maintain
- Clear separation of concerns

Depends on PR #5977 (context menu extension API)
@Myestery Myestery marked this pull request as ready for review October 9, 2025 01:10
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 9, 2025
collectNodeMenuItems(node: LGraphNode): IContextMenuValue[] {
const items: IContextMenuValue[] = []

for (const ext of this.extensions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Comment on lines +9 to +10
let mockCanvas: LGraphCanvas
let mockNode: LGraphNode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could you use a factory to make these per-testcase instead of keeping them in the describe scope? That could also add some type safety via Partial

Also, I don't love things being called mock that aren't using the mocking system, but that's a lesser issue.

Copy link
Contributor

@christian-byrne christian-byrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using the same pattern as the selecton toolbox API

const extensionToolboxCommands = computed<ComfyCommandImpl[]>(() => {
const commandIds = new Set<string>(
canvasStore.selectedItems
.map(
(item) =>
extensionService
.invokeExtensions('getSelectionToolboxCommands', item)
.flat() as string[]
)
.flat()
)
return Array.from(commandIds)
.map((commandId) => commandStore.getCommand(commandId))
.filter((command): command is ComfyCommandImpl => command !== undefined)
})

comfyApp.extensions is deprecated and invokeExtensions is the newer API I would like to be using if possible.

@christian-byrne christian-byrne added Public API Affects or interacts with the public API surface (affecting custom node or extension authors) area:context-menus labels Oct 9, 2025
Refactored collectCanvasMenuItems and collectNodeMenuItems to use the
standardized invokeExtensions pattern from extensionService, matching
the approach used in SelectionToolbox.

This simplifies the code and provides consistent error handling across
all extension invocations.
- Test getCanvasMenuItems and getNodeMenuItems extension methods
- Verify results are collected into flat array from multiple extensions
- Add submenu tests with proper submenu.options structure
- Support menu separators (null items)
- Test extensions without menu methods are skipped
- Use extensionService.invokeExtensions directly
- Configure Pinia with stubActions: false
@christian-byrne christian-byrne merged commit eeb0977 into main Oct 10, 2025
26 checks passed
@christian-byrne christian-byrne deleted the contextmenu-for-extensions branch October 10, 2025 01:37
@arjansingh arjansingh mentioned this pull request Oct 11, 2025
arjansingh added a commit that referenced this pull request Oct 11, 2025
## What's Changed

### 🚀 Features
- Implement DOMWidget for vue (#6006)
- Implement drop-on-canvas + linkconnectoradapter consolidation (#5898)
- Vuenodes/audio widgets (#5627)
- Allow reordering of linked subgraph widgets (#5981)
- Contextmenu Monkeypatch Standardization (#5977)
- Fix/vue nodes snap to grid (#5973)
- Select Vue Nodes After Drag (#5863)
- fix Vue node widgets should be in disabled state if their slots are
connected with a link (#5834)

### 🐛 Bug Fixes
- [bugfix] Fix update-playwright-expectations workflow missing frontend
build (#6005)
- Fix: Reset size when collapsing (#6004)
- fix: misc LOD polish (#6001)
- Fix: Allow uncoloring Vue Nodes (#5991)
- [ci] Fix detached HEAD state in Playwright update workflow (#5985)
- Close zoom menu when toggling minimap visibility (#5974)

### 🔧 Maintenance
- Devex: Improve dev server (#6002)
- CI: Add concurrency checks to PR workflows (#6000)
- [feat] Auto-remove New Browser Test Expectations label after workflow
completes (#5998)
- CI: Simplify update playwright expectations (maybe) (#5994)
- Lint: Add tailwind linter (#5984)
- [feat] Auto-remove claude-review label after CI review completes
(#5983)
- Fix CI: Remove explicit repository parameter causing non-reproducible
test results (#5950)
- refactor: Reorganize GitHub Actions for better reusability (#5949)
- devex: Update CODEOWNERS (#5999)
- Docs: Update agent instructions about style classes (#5990)
- Style: Fix move cursors that should be grabs (#5989)
- Workflow templates review (#5975)

**Full Changelog**:
v1.29.0...v1.29.1

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6012-1-29-1-2896d73d365081b08418f46934651c41)
by [Unito](https://www.unito.io)

Co-authored-by: arjansingh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:context-menus Public API Affects or interacts with the public API surface (affecting custom node or extension authors) size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants