From 3e9835bafb5ba16c1853a68f395428b31a8093f0 Mon Sep 17 00:00:00 2001 From: Aleksandr Grenishin Date: Tue, 13 Feb 2024 14:48:47 +0300 Subject: [PATCH] fix: server validation error rendering (#604) Co-authored-by: nd0ut --- abstract/UploaderBlock.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/abstract/UploaderBlock.js b/abstract/UploaderBlock.js index fad7f6129..79b2f488f 100644 --- a/abstract/UploaderBlock.js +++ b/abstract/UploaderBlock.js @@ -137,7 +137,7 @@ export class UploaderBlock extends ActivityBlock { if (!this.$['*uploadCollection']) { let uploadCollection = new TypedCollection({ typedSchema: uploadEntrySchema, - watchList: ['uploadProgress', 'fileInfo', 'errors', 'cdnUrl', 'isUploading'], + watchList: ['uploadProgress', 'uploadError', 'fileInfo', 'errors', 'cdnUrl', 'isUploading'], }); this.$['*uploadCollection'] = uploadCollection; } @@ -498,9 +498,6 @@ export class UploaderBlock extends ActivityBlock { entry.setValue('errors', errors); } - /** @private */ - _debouncedRunFileValidators = debounce(this._runFileValidators.bind(this), 100); - /** * @private * @param {string[]} [entryIds] @@ -626,16 +623,20 @@ export class UploaderBlock extends ActivityBlock { this._flushOutputItems(); const uploadCollection = this.uploadCollection; - const updatedEntryIds = [ + const entriesToRunValidation = [ ...new Set( Object.entries(changeMap) - .filter(([key]) => key !== 'errors') + .filter(([key]) => ['uploadError', 'fileInfo'].includes(key)) .map(([, ids]) => [...ids]) .flat(), ), ]; - this._debouncedRunFileValidators(updatedEntryIds); + entriesToRunValidation.length > 0 && + setTimeout(() => { + // We can't modify entry properties in the same tick, so we need to wait a bit + this._runFileValidators(entriesToRunValidation); + }); if (changeMap.uploadProgress) { for (const entryId of changeMap.uploadProgress) {