From 2b31fa47ff1f1152057856c85cf8d9deefe776ba Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 18 Aug 2025 17:28:29 -0500 Subject: [PATCH] Add special util --- src/state/cache/post-shadow.ts | 10 +++++++++- src/state/queries/usePostThread/queryCache.ts | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/state/cache/post-shadow.ts b/src/state/cache/post-shadow.ts index 8693a6dbcf..8cc3dca1a4 100644 --- a/src/state/cache/post-shadow.ts +++ b/src/state/cache/post-shadow.ts @@ -30,11 +30,19 @@ export interface PostShadow { export const POST_TOMBSTONE = Symbol('PostTombstone') const emitter = new EventEmitter() -export const shadows: WeakMap< +const shadows: WeakMap< AppBskyFeedDefs.PostView, Partial > = new WeakMap() +/** + * Use with caution! This function returns the raw shadow data for a post. + * Prefer using `usePostShadow`. + */ +export function dangerousGetPostShadow(post: AppBskyFeedDefs.PostView) { + return shadows.get(post) +} + export function usePostShadow( post: AppBskyFeedDefs.PostView, ): Shadow | typeof POST_TOMBSTONE { diff --git a/src/state/queries/usePostThread/queryCache.ts b/src/state/queries/usePostThread/queryCache.ts index 4e286decbd..2c1fd603b0 100644 --- a/src/state/queries/usePostThread/queryCache.ts +++ b/src/state/queries/usePostThread/queryCache.ts @@ -9,7 +9,10 @@ import { } from '@atproto/api' import {type QueryClient} from '@tanstack/react-query' -import {shadows, updatePostShadow} from '#/state/cache/post-shadow' +import { + dangerousGetPostShadow, + updatePostShadow, +} from '#/state/cache/post-shadow' import {findAllPostsInQueryData as findAllPostsInExploreFeedPreviewsQueryData} from '#/state/queries/explore-feed-previews' import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '#/state/queries/notifications/feed' import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/queries/post-feed' @@ -86,7 +89,7 @@ export function createCacheMutator({ /* * Update parent data */ - const shadow = shadows.get(parent.value.post) + const shadow = dangerousGetPostShadow(parent.value.post) const prevOptimisticCount = shadow?.optimisticReplyCount || 0 const prevReplyCount = parent.value.post.replyCount || 0 updatePostShadow(queryClient, parent.value.post.uri, {