fix: blob URL leaks, Pinia reactivity, and prefill race condition

- Revoke blob URLs for images exceeding MAX_EXAMPLES in addImages/insertImagesAt

- Cap insertImagesAt to prevent growing past MAX_EXAMPLES

- Use store proxy instead of destructuring activeWorkflow (was always undefined)

- Only apply prefill to untouched form fields to avoid overwriting user edits

Amp-Thread-ID: https://ampcode.com/threads/T-019cf97c-2a79-72da-b6e8-9ed0275d1b1b
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-03-16 19:29:07 -07:00
parent 2cf8e645db
commit f7522bcaf6
3 changed files with 39 additions and 15 deletions

View File

@@ -151,26 +151,37 @@ function addImages(files: FileList) {
const remaining = MAX_EXAMPLES - exampleImages.value.length
if (remaining <= 0) return
const newImages = createExampleImages(files).slice(0, remaining)
const created = createExampleImages(files)
const newImages = created.slice(0, remaining)
for (const img of created.slice(remaining)) {
URL.revokeObjectURL(img.url)
}
if (newImages.length > 0) {
exampleImages.value = [...newImages, ...exampleImages.value]
}
}
function insertImagesAt(index: number, files: FileList) {
const newImages = createExampleImages(files)
if (newImages.length === 0) return
const created = createExampleImages(files)
if (created.length === 0) return
const remaining = MAX_EXAMPLES - exampleImages.value.length
const updated = [...exampleImages.value]
const remaining = MAX_EXAMPLES - exampleImages.value.length
const maxInsert =
remaining <= 0 ? Math.max(updated.length - index, 0) : remaining
const newImages = created.slice(0, maxInsert)
for (const img of created.slice(maxInsert)) {
URL.revokeObjectURL(img.url)
}
if (newImages.length === 0) return
if (remaining <= 0) {
const replacedImages = updated.splice(index, newImages.length, ...newImages)
for (const img of replacedImages) {
if (img.file) URL.revokeObjectURL(img.url)
}
} else {
updated.splice(index, 0, ...newImages.slice(0, remaining))
updated.splice(index, 0, ...newImages)
}
exampleImages.value = updated

View File

@@ -50,7 +50,7 @@ function getAssetIds(assets: AssetInfo[]): string[] {
export function useComfyHubPublishSubmission() {
const { profile } = useComfyHubProfileGate()
const { activeWorkflow } = useWorkflowStore()
const workflowStore = useWorkflowStore()
const workflowShareService = useWorkflowShareService()
const comfyHubService = useComfyHubService()
@@ -74,7 +74,9 @@ export function useComfyHubPublishSubmission() {
formData: ComfyHubPublishFormData
): Promise<void> {
const username = getUsername(profile.value)
const workflowFilename = getWorkflowFilename(activeWorkflow?.path)
const workflowFilename = getWorkflowFilename(
workflowStore.activeWorkflow?.path
)
const assetIds = getAssetIds(
await workflowShareService.getShareableAssets()
)

View File

@@ -22,9 +22,9 @@ export type ComfyHubPublishStep = (typeof PUBLISH_STEPS)[number]
const cachedPrefills = new Map<string, PublishPrefill>()
function createDefaultFormData(): ComfyHubPublishFormData {
const { activeWorkflow } = useWorkflowStore()
const workflowStore = useWorkflowStore()
return {
name: activeWorkflow?.filename ?? '',
name: workflowStore.activeWorkflow?.filename ?? '',
description: '',
tags: [],
thumbnailType: 'image',
@@ -88,15 +88,26 @@ export function useComfyHubPublishWizard() {
}
function applyPrefill(prefill: PublishPrefill) {
const defaults = createDefaultFormData()
const current = formData.value
formData.value = {
...current,
description: prefill.description ?? current.description,
tags: prefill.tags?.length ? prefill.tags : current.tags,
thumbnailType: prefill.thumbnailType ?? current.thumbnailType,
exampleImages: prefill.sampleImageUrls?.length
? createExampleImagesFromUrls(prefill.sampleImageUrls)
: current.exampleImages
description:
current.description === defaults.description
? (prefill.description ?? current.description)
: current.description,
tags:
current.tags.length === 0 && prefill.tags?.length
? prefill.tags
: current.tags,
thumbnailType:
current.thumbnailType === defaults.thumbnailType
? (prefill.thumbnailType ?? current.thumbnailType)
: current.thumbnailType,
exampleImages:
current.exampleImages.length === 0 && prefill.sampleImageUrls?.length
? createExampleImagesFromUrls(prefill.sampleImageUrls)
: current.exampleImages
}
}