Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/platform/assets/composables/useUploadModelWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ export function useUploadModelWizard(modelTypes: Ref<ModelTypeOption[]>) {

uploadStatus.value = 'success'
currentStep.value = 3

// Emit event for store to invalidate caches
window.dispatchEvent(
new CustomEvent('model-upload-success', {
detail: { modelType: selectedModelType.value }
})
)

return true
} catch (error) {
console.error('Failed to upload asset:', error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, toValue, watch } from 'vue'
import type { MaybeRefOrGetter } from 'vue'
import { useEventListener } from '@vueuse/core'

import { isCloud } from '@/platform/distribution/types'
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
Expand Down Expand Up @@ -80,6 +81,22 @@ export function useAssetWidgetData(
{ immediate: true }
)

// Listen for model upload events and refetch data
if (typeof window !== 'undefined') {
useEventListener(window, 'model-upload-success', async (event: Event) => {
const currentNodeType = toValue(nodeType)
if (!currentNodeType) return

const customEvent = event as CustomEvent<{ modelType: string }>
const uploadedModelType = customEvent.detail?.modelType

// Only refetch if the uploaded model type matches this widget's category
if (uploadedModelType && uploadedModelType === category.value) {
await assetsStore.updateModelsForNodeType(currentNodeType)
}
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Add error handling for async store update.

The event listener correctly filters by category to minimize unnecessary API calls. However, the call to assetsStore.updateModelsForNodeType is not wrapped in error handling.

Apply this diff to add error handling:

     // Listen for model upload events and refetch data
     if (typeof window !== 'undefined') {
       useEventListener(window, 'model-upload-success', async (event: Event) => {
         const currentNodeType = toValue(nodeType)
         if (!currentNodeType) return
 
         const customEvent = event as CustomEvent<{ modelType: string }>
         const uploadedModelType = customEvent.detail?.modelType
 
         // Only refetch if the uploaded model type matches this widget's category
         if (uploadedModelType && uploadedModelType === category.value) {
-          await assetsStore.updateModelsForNodeType(currentNodeType)
+          try {
+            await assetsStore.updateModelsForNodeType(currentNodeType)
+          } catch (error) {
+            console.error('Failed to refresh models after upload:', error)
+          }
         }
       })
     }

As per coding guidelines: "Implement proper error handling"

🤖 Prompt for AI Agents
In src/renderer/extensions/vueNodes/widgets/composables/useAssetWidgetData.ts
around lines 84 to 98, the async call to assetsStore.updateModelsForNodeType
inside the model-upload-success event listener lacks error handling; wrap the
await call in a try/catch, and in the catch block log the error with contextual
information (including currentNodeType and category.value) so failures are
visible and safe to ignore for the UI; ensure the listener remains async and
does not rethrow the error.


return {
category,
assets,
Expand Down
Loading