refactor: improve feed loading and infinite scroll reliability

- Add debouncing and loading state to InfiniteScroll component to prevent duplicate entries
- Refactor updateAllFeed into smaller, focused functions for better maintainability
- Add proper error handling and type assertions
- Optimize test performance with networkidle waits and better selectors
- Fix strict mode violations in Playwright tests
- Clean up test configuration by commenting out unused browser targets
This commit is contained in:
Matthew Raymer
2025-03-31 09:17:15 +00:00
parent 8c8e4ec28e
commit 34dc4149f5
6 changed files with 3007 additions and 22370 deletions

View File

@@ -14,6 +14,8 @@ export default class InfiniteScroll extends Vue {
readonly distance!: number;
private observer!: IntersectionObserver;
private isInitialRender = true;
private isLoading = false;
private debounceTimeout: number | null = null;
updated() {
if (!this.observer) {
@@ -35,13 +37,28 @@ export default class InfiniteScroll extends Vue {
if (this.observer) {
this.observer.disconnect();
}
if (this.debounceTimeout) {
window.clearTimeout(this.debounceTimeout);
}
}
@Emit("reached-bottom")
handleIntersection(entries: IntersectionObserverEntry[]) {
const entry = entries[0];
if (entry.isIntersecting) {
return true;
if (entry.isIntersecting && !this.isLoading) {
// Debounce the intersection event
if (this.debounceTimeout) {
window.clearTimeout(this.debounceTimeout);
}
this.debounceTimeout = window.setTimeout(() => {
this.isLoading = true;
this.$emit("reached-bottom", true);
// Reset loading state after a short delay
setTimeout(() => {
this.isLoading = false;
}, 1000);
}, 300);
}
return false;
}