From 996871d88ba3298ed53705a6c865cdfe5ede961a Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 3 Dec 2024 01:11:11 +0000 Subject: [PATCH] Prefetch adjacent Home pages (#6904) --- src/view/com/feeds/FeedPage.tsx | 6 ++++-- src/view/com/posts/Feed.tsx | 4 ++-- src/view/screens/Home.tsx | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/view/com/feeds/FeedPage.tsx b/src/view/com/feeds/FeedPage.tsx index 1028d7e641f..44e90a55195 100644 --- a/src/view/com/feeds/FeedPage.tsx +++ b/src/view/com/feeds/FeedPage.tsx @@ -32,6 +32,7 @@ const POLL_FREQ = 60e3 // 60sec export function FeedPage({ testID, isPageFocused, + isPageAdjacent, feed, feedParams, renderEmptyState, @@ -42,6 +43,7 @@ export function FeedPage({ feed: FeedDescriptor feedParams?: FeedParams isPageFocused: boolean + isPageAdjacent: boolean renderEmptyState: () => JSX.Element renderEndOfFeed?: () => JSX.Element savedFeedConfig?: AppBskyActorDefs.SavedFeed @@ -111,11 +113,11 @@ export function FeedPage({ { - if (enabled) { + if (enabled && !disablePoll) { const timeSinceFirstLoad = Date.now() - lastFetchRef.current // DISABLED need to check if this is causing random feed refreshes -prf /*if (timeSinceFirstLoad > REFRESH_AFTER) { @@ -231,7 +231,7 @@ let Feed = ({ checkForNewRef.current() } } - }, [enabled, feed, queryClient, scrollElRef]) + }, [enabled, disablePoll, feed, queryClient, scrollElRef]) React.useEffect(() => { let cleanup1: () => void | undefined, cleanup2: () => void | undefined const subscription = AppState.addEventListener('change', nextAppState => { diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index cadfb489034..91c9ae69abb 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -233,7 +233,7 @@ function HomeScreenReady({ onPageScrollStateChanged={onPageScrollStateChanged} renderTabBar={renderTabBar}> {pinnedFeedInfos.length ? ( - pinnedFeedInfos.map(feedInfo => { + pinnedFeedInfos.map((feedInfo, index) => { const feed = feedInfo.feedDescriptor if (feed === 'following') { return ( @@ -241,6 +241,7 @@ function HomeScreenReady({ key={feed} testID="followingFeedPage" isPageFocused={selectedFeed === feed} + isPageAdjacent={Math.abs(selectedIndex - index) === 1} feed={feed} feedParams={homeFeedParams} renderEmptyState={renderFollowingEmptyState} @@ -254,6 +255,7 @@ function HomeScreenReady({ key={feed} testID="customFeedPage" isPageFocused={selectedFeed === feed} + isPageAdjacent={Math.abs(selectedIndex - index) === 1} feed={feed} renderEmptyState={renderCustomFeedEmptyState} savedFeedConfig={savedFeedConfig} @@ -273,6 +275,7 @@ function HomeScreenReady({