Skip to content
Merged
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
25 changes: 24 additions & 1 deletion src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
isEditable: false,
isLastInserted: false,
embeddedImageList: [],
loadIntersectionObserver: null,

Check warning on line 175 in src/nodes/ImageView.vue

View check run for this annotation

Codecov / codecov/patch

src/nodes/ImageView.vue#L175

Added line #L175 was not covered by tests
}
},
computed: {
Expand Down Expand Up @@ -230,7 +231,29 @@
this.isLastInserted = true
}
})
this.loadPreview().catch(this.onImageLoadFailure)
},
mounted() {
this.$nextTick(() => {
// nextTick is necessary, intersection detection is slightly unreliable without it
const options = {
root: null,
threshold: 0,
}
const startImageLoad = (entries, observer) => {
if (entries[0].isIntersecting) {
observer.disconnect()
this.loadPreview().catch(this.onImageLoadFailure)
}
}
this.loadIntersectionObserver = new IntersectionObserver(
startImageLoad,
options,
)
this.loadIntersectionObserver.observe(this.$el)
})
},
beforeUnmount() {
this.loadIntersectionObserver?.disconnect()

Check warning on line 256 in src/nodes/ImageView.vue

View check run for this annotation

Codecov / codecov/patch

src/nodes/ImageView.vue#L234-L256

Added lines #L234 - L256 were not covered by tests
},
methods: {
async loadPreview() {
Expand Down
Loading