Repository navigation
refactor: load extensions from the bootstrap step, not extensionService #19092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { useSettingStore } from '@/platform/settings/settingStore' | ||
| import { bootstrapTracer } from '@/platform/telemetry/perf/bootstrapTracer' | ||
| import { reportError } from '@/platform/telemetry/reportError' | ||
| import { api } from '@/scripts/api' | ||
| import { useExtensionStore } from '@/stores/extensionStore' | ||
| import { getErrorMessage } from '@/utils/errorUtil' | ||
|
|
||
| const INLINED_CLOUD_EXTENSIONS = new Set([ | ||
| '/extensions/cloud/rum.js', | ||
| '/extensions/cloud/sentry.js' | ||
| ]) | ||
|
|
||
| export function shouldLoadExtension( | ||
| extension: string, | ||
| isCloudBuild: boolean | ||
| ): boolean { | ||
| if (extension.includes('extensions/core')) return false | ||
| return !isCloudBuild || !INLINED_CLOUD_EXTENSIONS.has(extension) | ||
| } | ||
|
|
||
| const MAX_NAMED_FAILED_EXTENSIONS = 10 | ||
|
|
||
| export interface ExtensionLoadFailure { | ||
| ext: string | ||
| error: unknown | ||
| } | ||
|
|
||
| /** | ||
| * Import one backend-provided extension, returning the failure rather than | ||
| * throwing, so one broken pack cannot abort the rest of the parallel load. | ||
| * | ||
| * Reporting deliberately does not happen here. A systemic failure — a backend | ||
| * restart, or a proxy serving HTML for every `.js` — fails every import in the | ||
| * list, and one report per extension is then unbounded. Off cloud that is | ||
| * actively harmful: with no sink live, each report is held in `reportError`'s | ||
| * 25-entry pending buffer, so a handful of broken packs during bootstrap would | ||
| * silently crowd out every later error in the session. The batch is reported | ||
| * once, by `reportExtensionLoadFailures`. | ||
| */ | ||
| async function importCustomExtension( | ||
| ext: string | ||
| ): Promise<ExtensionLoadFailure | undefined> { | ||
| try { | ||
| await import(/* @vite-ignore */ api.fileURL(ext)) | ||
| } catch (error) { | ||
| return { ext, error } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The paths go in the message because `reportError` writes its console line | ||
| * from the error, not from `options.tags`. The count is tagged; backend paths | ||
| * are unbounded and belong in context instead of an indexed facet. | ||
| */ | ||
| export function reportExtensionLoadFailures( | ||
| failures: ExtensionLoadFailure[] | ||
| ): void { | ||
| if (failures.length === 0) return | ||
|
|
||
| const named = failures.slice(0, MAX_NAMED_FAILED_EXTENSIONS) | ||
| const elided = failures.length - named.length | ||
| const paths = named.map(({ ext }) => ext).join(', ') | ||
| const noun = failures.length === 1 ? 'extension' : 'extensions' | ||
|
|
||
| reportError( | ||
| new Error( | ||
| `Error loading ${failures.length} ${noun}: ${paths}` + | ||
| (elided > 0 ? ` (+${elided} more)` : ''), | ||
| { cause: failures[0].error } | ||
| ), | ||
| { | ||
| errorType: 'error_loading_extension', | ||
| surface: 'platform', | ||
| level: 'warning', | ||
| tags: { failed_extension_count: failures.length }, | ||
| context: { | ||
| failures: named.map(({ ext, error }) => ({ | ||
| ext, | ||
| message: getErrorMessage(error) | ||
| })) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Loads the core extensions, then every extension served by the backend, in | ||
| * parallel. Core extensions load first because custom extensions may depend | ||
| * on them. | ||
| */ | ||
| export async function loadExtensions() { | ||
| const extensionStore = useExtensionStore() | ||
| extensionStore.loadDisabledExtensionNames( | ||
| useSettingStore().get('Comfy.Extension.Disabled') | ||
| ) | ||
|
|
||
| const extensions = await api.getExtensions() | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| await bootstrapTracer.settle( | ||
| 'bootstrap/extensions-load-core', | ||
| () => import('@/extensions/core/index') | ||
| ) | ||
| extensionStore.captureCoreExtensions() | ||
| const outcomes = await bootstrapTracer.settle( | ||
| 'bootstrap/extensions-load-custom', | ||
| () => | ||
| Promise.all( | ||
| extensions | ||
| .filter((extension) => | ||
| shouldLoadExtension(extension, __DISTRIBUTION__ === 'cloud') | ||
| ) | ||
| .map((ext) => importCustomExtension(ext)) | ||
| ) | ||
| ) | ||
| reportExtensionLoadFailures(outcomes.filter((outcome) => !!outcome)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.