diff --git a/src/state/queries/usePostThread/queryCache.ts b/src/state/queries/usePostThread/queryCache.ts index 871033395f..74ee13ff80 100644 --- a/src/state/queries/usePostThread/queryCache.ts +++ b/src/state/queries/usePostThread/queryCache.ts @@ -93,6 +93,7 @@ export function createCacheMutator({ const opDid = getRootPostAtUri(existingParent.value.post)?.host const nextItem = thread.at(i + 1) const isReplyToRoot = existingParent.depth === 0 + const isReplyBelowRoot = existingParent.depth > 0 const isEndOfReplyChain = !nextItem || nextItem.depth <= existingParent.depth const firstReply = replies.at(0) @@ -103,17 +104,19 @@ export function createCacheMutator({ : false /* - * Always insert replies if the following conditions are met. + * Always insert replies if the following conditions are met. Max + * depth checks are handled below. */ const shouldAlwaysInsertReplies = isReplyToRoot || - params.view === 'tree' || + (params.view === 'tree' && isReplyBelowRoot) || (params.view === 'linear' && isEndOfReplyChain) /* - * Maybe insert replies if the replier is the OP and certain conditions are met + * Maybe insert replies if the replier is the OP and certain + * conditions are met */ const shouldReplaceWithOPReplies = - !isReplyToRoot && params.view === 'linear' && opIsReplier + params.view === 'linear' && opIsReplier && isReplyBelowRoot if (shouldAlwaysInsertReplies || shouldReplaceWithOPReplies) { const branch = getBranch(thread, i, existingParent.depth) diff --git a/src/state/queries/usePostThread/utils.ts b/src/state/queries/usePostThread/utils.ts index b8ab340d87..265bf7f5fb 100644 --- a/src/state/queries/usePostThread/utils.ts +++ b/src/state/queries/usePostThread/utils.ts @@ -33,6 +33,12 @@ export function getRootPostAtUri(post: AppBskyFeedDefs.PostView) { AppBskyFeedPost.isRecord, ) ) { + /** + * If the record has no `reply` field, it is a root post. + */ + if (!post.record.reply) { + return new AtUri(post.uri) + } if (post.record.reply?.root?.uri) { return new AtUri(post.record.reply.root.uri) }