Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(files): properly reset preview component #45432

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 13 additions & 4 deletions apps/files/src/components/FileEntry/FileEntryPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
:class="{'files-list__row-icon-preview--loaded': backgroundFailed === false}"
loading="lazy"
:src="previewUrl"
@error="backgroundFailed = true"
@error="onBackgroundError"
@load="backgroundFailed = false">

<FileIcon v-else v-once />
Expand Down Expand Up @@ -218,12 +218,21 @@ export default Vue.extend({
},

methods: {
// Called from FileEntry
reset() {
if (this.backgroundFailed === true && this.$refs.previewImg) {
// Reset background state to cancel any ongoing requests
this.backgroundFailed = undefined
if (this.$refs.previewImg) {
this.$refs.previewImg.src = ''
}
// Reset background state
this.backgroundFailed = undefined
},

onBackgroundError(event) {
// Do not fail if we just reset the background
if (event.target?.src === '') {
return
}
this.backgroundFailed = true
},

t,
Expand Down
9 changes: 6 additions & 3 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ export default defineComponent({
* When the source changes, reset the preview
* and fetch the new one.
*/
source() {
this.resetState()
source(a: Node, b: Node) {
if (a.source !== b.source) {
this.resetState()
}
},
},

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

this.$refs.preview.reset()
// Reset the preview state
this.$refs?.preview?.reset?.()

// Close menu
this.openedMenu = false
Expand Down
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading