Skip to content

Commit

Permalink
Merge pull request #1340 from nextcloud-libraries/fix/do-not-attach-p…
Browse files Browse the repository at this point in the history
…review-loader-to-dom

fix(FilePicker): Do not append image preloader to DOM
  • Loading branch information
susnux authored May 27, 2024
2 parents 92ad396 + 63bc555 commit 495fe16
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/components/FilePicker/FilePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

<script setup lang="ts">
import { FileType, type Node } from '@nextcloud/files'
import { computed, ref, watch } from 'vue'
import { computed, ref, watchEffect } from 'vue'
import { getPreviewURL } from '../../composables/preview'
import { t } from '../../utils/l10n'
import IconFile from 'vue-material-design-icons/File.vue'
import IconFolder from 'vue-material-design-icons/Folder.vue'
Expand All @@ -32,17 +31,16 @@ const previewURL = computed(() => getPreviewURL(props.node, { cropPreview: props
const isFile = computed(() => props.node.type === FileType.File)
const canLoadPreview = ref(false)
watch(previewURL, () => {
watchEffect(() => {
canLoadPreview.value = false
if (previewURL.value) {
const loader = document.createElement('img')
const loader = new Image()
loader.src = previewURL.value.href
loader.onerror = () => loader.remove()
loader.onload = () => { canLoadPreview.value = true; loader.remove() }
document.body.appendChild(loader)
}
}, { immediate: true })
})
</script>

<script lang="ts">
Expand Down

0 comments on commit 495fe16

Please sign in to comment.