Skip to content

Commit

Permalink
load-more: Stop loader if component is unmounted [#533]
Browse files Browse the repository at this point in the history
If the `<load-more>` component is unmounted while it is loading, AND
while `is-fully-loaded="false"`, the loader function will get stuck in
an infinite loop.  Stop the loader from running by explicitly noting the
component is no longer visible when it is unmounted.
  • Loading branch information
josh-berry committed Sep 22, 2024
1 parent 0e2421b commit 12748db
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/load-more.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ export default defineComponent({
/** Are we currently trying to load more data (i.e. waiting for load()
* to return)? */
isLoading: false,
/** We keep a ref to the IntersectionObserver so we can disconnect it
* when the component is unmounted. */
observer: undefined as IntersectionObserver | undefined,
}),
computed: {
Expand Down Expand Up @@ -112,6 +108,11 @@ export default defineComponent({
observer.observe(this.el!);
},
beforeUnmount() {
// We must explicitly clear isVisible here because if we're in the middle of
// loadMore() when the component is unmounted, AND if `!this.isFullyLoaded`
// at unmount time, then loadMore() will continue to loop infinitely.
this.isVisible = false;
callbacks.delete(this.el!);
observer.unobserve(this.el!);
},
Expand Down

0 comments on commit 12748db

Please sign in to comment.