@@ -104,6 +104,7 @@ export default class extends Controller {
104104 private backgroundSyncTimeoutId : ReturnType < typeof setTimeout > | null = null ;
105105 private latestManifestRevision : string | null = null ;
106106 private isBackgroundSyncEnabled : boolean = false ;
107+ private uploadErrorFallbackLabel : string = "Upload failed. Please try again." ;
107108 private readonly focusHandler = ( ) : void => {
108109 void this . checkForManifestUpdates ( ) ;
109110 } ;
@@ -115,6 +116,13 @@ export default class extends Controller {
115116
116117 connect ( ) : void {
117118 this . isConnected = true ;
119+ if ( this . hasUploadErrorTarget ) {
120+ const textEl = this . uploadErrorTarget . querySelector ( "[data-error-text]" ) ;
121+ const initialText = textEl ?. textContent ?. trim ( ) ;
122+ if ( initialText ) {
123+ this . uploadErrorFallbackLabel = initialText ;
124+ }
125+ }
118126 void this . fetchAssets ( ) ;
119127 this . setupDropzone ( ) ;
120128 this . isBackgroundSyncEnabled = this . getBackgroundSyncIntervalMs ( ) > 0 ;
@@ -513,7 +521,7 @@ export default class extends Controller {
513521 }
514522
515523 private async checkForManifestUpdates ( ) : Promise < void > {
516- if ( this . isUploading ) {
524+ if ( this . isUploading || this . isLoading ) {
517525 return ;
518526 }
519527
@@ -560,7 +568,9 @@ export default class extends Controller {
560568 }
561569
562570 private async reloadAssetsAfterConfirmation ( ) : Promise < void > {
563- await this . fetchAssets ( ) ;
571+ if ( ( await this . fetchAssets ( ) ) === null ) {
572+ return ;
573+ }
564574 this . showUploadStatus ( "success" ) ;
565575 setTimeout ( ( ) => this . showUploadStatus ( "none" ) , 3000 ) ;
566576 }
@@ -572,13 +582,7 @@ export default class extends Controller {
572582 }
573583
574584 private getUploadErrorFallbackLabel ( ) : string {
575- if ( this . hasUploadErrorTarget ) {
576- const textEl = this . uploadErrorTarget . querySelector ( "[data-error-text]" ) ;
577- if ( textEl && textEl . textContent !== null && textEl . textContent !== "" ) {
578- return textEl . textContent ;
579- }
580- }
581- return "Upload failed. Please try again." ;
585+ return this . uploadErrorFallbackLabel ;
582586 }
583587
584588 private normalizeManifestData ( data : { urls ?: string [ ] ; revision ?: string } ) : { urls : string [ ] ; revision : string } {
0 commit comments