Skip to content

Commit 9227e69

Browse files
skjnldsvsusnux
authored andcommitted
fix(files): properly reset preview component
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 278aafd commit 9227e69

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

apps/files/src/components/FileEntry/FileEntryPreview.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
:class="{'files-list__row-icon-preview--loaded': backgroundFailed === false}"
4040
loading="lazy"
4141
:src="previewUrl"
42-
@error="backgroundFailed = true"
42+
@error="onBackgroundError"
4343
@load="backgroundFailed = false">
4444

4545
<FileIcon v-else v-once />
@@ -218,12 +218,21 @@ export default Vue.extend({
218218
},
219219
220220
methods: {
221+
// Called from FileEntry
221222
reset() {
222-
if (this.backgroundFailed === true && this.$refs.previewImg) {
223+
// Reset background state to cancel any ongoing requests
224+
this.backgroundFailed = undefined
225+
if (this.$refs.previewImg) {
223226
this.$refs.previewImg.src = ''
224227
}
225-
// Reset background state
226-
this.backgroundFailed = undefined
228+
},
229+
230+
onBackgroundError(event) {
231+
// Do not fail if we just reset the background
232+
if (event.target?.src === '') {
233+
return
234+
}
235+
this.backgroundFailed = true
227236
},
228237
229238
t,

apps/files/src/components/FileEntryMixin.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ export default defineComponent({
175175
* When the source changes, reset the preview
176176
* and fetch the new one.
177177
*/
178-
source() {
179-
this.resetState()
178+
source(a: Node, b: Node) {
179+
if (a.source !== b.source) {
180+
this.resetState()
181+
}
180182
},
181183
},
182184

@@ -189,7 +191,8 @@ export default defineComponent({
189191
// Reset loading state
190192
this.loading = ''
191193

192-
this.$refs.preview.reset()
194+
// Reset the preview state
195+
this.$refs?.preview?.reset?.()
193196

194197
// Close menu
195198
this.openedMenu = false

0 commit comments

Comments
 (0)