From dfa50e51a668ff0178576f3d001a23f32c3f40ea Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 13 Sep 2024 03:45:48 +0100 Subject: [PATCH 1/2] Revert "Fix notification scroll jump (#5297)" This reverts commit e0d9e75407b053dd3b7a3472f925d8cd4bd92d45. --- src/state/queries/notifications/util.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index 133d3ebc2e..e0ee02294e 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -175,19 +175,9 @@ async function fetchSubjects( }> { const postUris = new Set() const packUris = new Set() - - const postUrisWithLikes = new Set() - const postUrisWithReposts = new Set() - for (const notif of groupedNotifs) { if (notif.subjectUri?.includes('app.bsky.feed.post')) { postUris.add(notif.subjectUri) - if (notif.type === 'post-like') { - postUrisWithLikes.add(notif.subjectUri) - } - if (notif.type === 'repost') { - postUrisWithReposts.add(notif.subjectUri) - } } else if ( notif.notification.reasonSubject?.includes('app.bsky.graph.starterpack') ) { @@ -216,15 +206,6 @@ async function fetchSubjects( AppBskyFeedPost.validateRecord(post.record).success ) { postsMap.set(post.uri, post) - - // HACK. In some cases, the appview appears to lag behind and returns empty counters. - // To prevent scroll jump due to missing metrics, fill in 1 like/repost instead of 0. - if (post.likeCount === 0 && postUrisWithLikes.has(post.uri)) { - post.likeCount = 1 - } - if (post.repostCount === 0 && postUrisWithReposts.has(post.uri)) { - post.repostCount = 1 - } } } for (const pack of packsChunks.flat()) { From 7a3fc8cdc29c824191ea929a034c193526763abc Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 13 Sep 2024 03:46:01 +0100 Subject: [PATCH 2/2] Query notifications first --- src/state/queries/post-thread.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts index 83ca60c2ae..a569cb1605 100644 --- a/src/state/queries/post-thread.ts +++ b/src/state/queries/post-thread.ts @@ -408,10 +408,14 @@ export function* findAllPostsInQueryData( } } } - for (let post of findAllPostsInFeedQueryData(queryClient, uri)) { + for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) { + // Check notifications first. If you have a post in notifications, + // it's often due to a like or a repost, and we want to prioritize + // a post object with >0 likes/reposts over a stale version with no + // metrics in order to avoid a notification->post scroll jump. yield postViewToPlaceholderThread(post) } - for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) { + for (let post of findAllPostsInFeedQueryData(queryClient, uri)) { yield postViewToPlaceholderThread(post) } for (let post of findAllPostsInQuoteQueryData(queryClient, uri)) {