Skip to content

Conversation

@snomiao
Copy link
Member

@snomiao snomiao commented Sep 16, 2025

Summary

  • Extracted LiteGraph singleton instance into a separate module to break circular dependency chains
  • Improves module loading order and prevents initialization issues
  • Maintains the same API and functionality

Context

This PR addresses the second circular dependency issue mentioned in #5533:

  • The circular import chain: SubgraphNode → LGraphNode → litegraph.ts → SubgraphNode
  • When litegraph.ts exports modules, it triggers loading of SubgraphNode which tries to extend LGraphNode, but LGraphNode imports from litegraph.ts causing circular initialization

Solution

By extracting the LiteGraph singleton into a separate LiteGraphSingleton.ts module, we break the circular dependency chain and ensure proper module initialization order.

Changes

  • Created new LiteGraphSingleton.ts module to hold the singleton instance
  • Updated all imports across the codebase to reference the singleton from the new module
  • No functional changes, purely a refactoring to improve module structure

Test Plan

  • All existing tests pass
  • No runtime errors from circular dependencies
  • Module loading order is now deterministic

🤖 Generated with Claude Code

@snomiao snomiao requested a review from a team as a code owner September 16, 2025 06:02
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Sep 16, 2025
@github-actions
Copy link

github-actions bot commented Sep 16, 2025

🎭 Playwright Test Results

⚠️ Tests passed with flaky tests

⏰ Completed at: 09/24/2025, 03:00:45 AM UTC

📈 Summary

  • Total Tests: 459
  • Passed: 428 ✅
  • Failed: 0
  • Flaky: 2 ⚠️
  • Skipped: 29 ⏭️

📊 Test Reports by Browser

  • chromium: View Report • ✅ 421 / ❌ 0 / ⚠️ 2 / ⏭️ 29
  • chromium-2x: View Report • ✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0
  • chromium-0.5x: View Report • ✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0
  • mobile-chrome: View Report • ✅ 4 / ❌ 0 / ⚠️ 0 / ⏭️ 0

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

@snomiao snomiao force-pushed the sno-solve-circular-dependency branch from 55fb7ce to a6480d1 Compare September 16, 2025 08:16
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Sep 16, 2025
@github-actions
Copy link

🔧 Auto-fixes Applied

This PR has been automatically updated to fix linting and formatting issues.

⚠️ Important: Your local branch is now behind. Run git pull before making additional changes to avoid conflicts.

Changes made:

  • ESLint auto-fixes
  • Prettier formatting

@snomiao snomiao force-pushed the sno-solve-circular-dependency branch from c1ee727 to eef0560 Compare September 16, 2025 08:43
Copy link
Contributor

@webfiltered webfiltered left a comment

Choose a reason for hiding this comment

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

I might be misreading the PR - the current global LiteGraph object is already a singleton. Could you not just move that instead? It would be a significantly smaller change.

@snomiao snomiao force-pushed the sno-solve-circular-dependency branch from eef0560 to 8bb99a3 Compare September 16, 2025 09:11
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Sep 16, 2025
@snomiao
Copy link
Member Author

snomiao commented Sep 16, 2025

I might be misreading the PR - the current global LiteGraph object is already a singleton. Could you not just move that instead? It would be a significantly smaller change.

Hey @webfiltered, You did not misreading!

I 've renamed it just wanna ensure we are importing direct from the module insteadof from barrel file litegraph.ts. Using a different name helps avoid any confusion between two export files in future.

I think better name is LiteGraphInternal now, just pushed new commit for it : D

@snomiao snomiao force-pushed the sno-solve-circular-dependency branch 2 times, most recently from aa4083f to daa76ef Compare September 16, 2025 09:33
@webfiltered
Copy link
Contributor

I might be misreading the PR - the current global LiteGraph object is already a singleton. Could you not just move that instead? It would be a significantly smaller change.

Hey @webfiltered, You did not misreading!

I 've renamed it just wanna ensure we are importing direct from the module insteadof from barrel file litegraph.ts. Using a different name helps avoid any confusion between two export files in future.

I think better name is LiteGraphInternal now, just pushed new commit for it : D

I'm still a bit confused - the imports should always work so long as you don't mess with the barrel file and import from it first. I balanced this a long while back, and messing with it is complex and frustrating to debug (especially with the ecosystem using the LiteGraph global var).

I just ran fix-verbatim-module-syntax npm package on another branch, and had CC convert the script to a vue version then ran it again. It all seems to be working fine.

PTAL: https://github.com/Comfy-Org/ComfyUI_frontend/compare/verbatim-module-syntax?expand=1

@webfiltered
Copy link
Contributor

Argh ran the wrong tests. Okay, I see the error you saw. This is actually just an issue with the test files.

@webfiltered
Copy link
Contributor

Yeah, can fix this easily by doing type imports properly:

import { type ThingToImport } from '@/file'

This still imports the file when running tests. We don't notice it in prod because it uses different systems (vite/bundle).

Should be:

import type { ThingToImport } from '@/file'

This type of import is only used for type information, pre-compile - doesn't exist at runtime.

@snomiao
Copy link
Member Author

snomiao commented Sep 16, 2025

Argh ran the wrong tests. Okay, I see the error you saw. This is actually just an issue with the test files.

I think we can merge your solution as first step:

import { type ThingToImport } from '@/file'

and then gradually refactor in following PRs into:

import type { ThingToImport } from '@/file'

to make things work smoothy, WDYT? @webfiltered @DrJKL @christian-byrne

@webfiltered
Copy link
Contributor

I think if we're going to do this change and touch all the imports, we may as well just do it all at once. I would not want to keep having to sanity check this repeatedly.

Pretty sure there's a linter that can auto-fix the imports. Failing that, we can just stuff the ast-grep I used into the pre-commit - it was very fast.

If there are more issues in future, it's just from direct importing. Runtime imports should be via the barrel, not direct importing from internal LiteGraph files.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Sep 17, 2025
@github-actions
Copy link

🔧 Auto-fixes Applied

This PR has been automatically updated to fix linting and formatting issues.

⚠️ Important: Your local branch is now behind. Run git pull before making additional changes to avoid conflicts.

Changes made:

  • ESLint auto-fixes
  • Prettier formatting

@snomiao snomiao marked this pull request as draft September 17, 2025 15:03
@snomiao snomiao force-pushed the sno-solve-circular-dependency branch 2 times, most recently from 95e0f09 to 8468b4e Compare September 18, 2025 12:13
@snomiao snomiao force-pushed the sno-solve-circular-dependency branch from 8468b4e to 4a2007f Compare September 22, 2025 21:14
@snomiao snomiao marked this pull request as ready for review September 22, 2025 21:30
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 22, 2025
@snomiao snomiao force-pushed the sno-solve-circular-dependency branch from 4a2007f to d866ef7 Compare September 24, 2025 02:49
@snomiao
Copy link
Member Author

snomiao commented Sep 30, 2025

Closed this as may not needed anymore since i18n locales workflow fixed by another approach #5775

@snomiao snomiao closed this Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants