Skip to content

Commit bc8383d

Browse files
ELin2025claude
andcommitted
fix(frontend): guard against stale upload response after clear
Use preview URL as a token to detect if the user cleared during an in-flight upload and discard the stale response. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 394dca9 commit bc8383d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

frontend/src/app/workspace/component/hugging-face-audio-upload/hugging-face-audio-upload.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export class HuggingFaceAudioUploadComponent extends FieldType<FieldTypeConfig>
8787
return;
8888
}
8989
this.revokePreviewUrl();
90-
this.localPreviewUrl = URL.createObjectURL(file);
90+
const previewUrl = URL.createObjectURL(file);
91+
this.localPreviewUrl = previewUrl;
9192
this.isUploading = true;
9293

9394
try {
@@ -102,6 +103,9 @@ export class HuggingFaceAudioUploadComponent extends FieldType<FieldTypeConfig>
102103
}
103104
)
104105
);
106+
// If the user clicked Clear while the upload was in flight,
107+
// localPreviewUrl will have been revoked/reset — discard the stale response.
108+
if (this.localPreviewUrl !== previewUrl) return;
105109
this.fileName = response.fileName || file.name;
106110
this.formControl.setValue(response.path);
107111
if (typeof this.key === "string" && this.model) {
@@ -111,6 +115,7 @@ export class HuggingFaceAudioUploadComponent extends FieldType<FieldTypeConfig>
111115
this.formControl.markAsTouched();
112116
this.formControl.updateValueAndValidity();
113117
} catch {
118+
if (this.localPreviewUrl !== previewUrl) return;
114119
this.clearAudio(input, false);
115120
this.errorMessage = "Could not upload this audio file.";
116121
} finally {

0 commit comments

Comments
 (0)