diff --git a/apps/renderer/src/atoms/feed.ts b/apps/renderer/src/atoms/feed.ts index d5a5d9e87e..0539db436c 100644 --- a/apps/renderer/src/atoms/feed.ts +++ b/apps/renderer/src/atoms/feed.ts @@ -20,6 +20,7 @@ export const useFeedUnreadIsDirty = (feedId: string) => { () => selectAtom(feedUnreadDirtySetAtom, (set) => { const isRealFeedId = isBizId(feedId) + if (isRealFeedId) return set.has(feedId) if (feedId.startsWith(ROUTE_FEED_IN_LIST) || feedId.startsWith(INBOX_PREFIX_ID)) { @@ -67,3 +68,7 @@ export const clearFeedUnreadDirty = (feedId: string) => { return newSet }) } + +export const clearAllFeedUnreadDirty = () => { + jotaiStore.set(feedUnreadDirtySetAtom, new Set()) +} diff --git a/apps/renderer/src/queries/entries.ts b/apps/renderer/src/queries/entries.ts index 2550bb9a5c..1c06c9bc57 100644 --- a/apps/renderer/src/queries/entries.ts +++ b/apps/renderer/src/queries/entries.ts @@ -159,17 +159,20 @@ export const useEntries = ({ initialPageParam: undefined, refetchOnWindowFocus: false, refetchOnReconnect: false, - refetchOnMount: fetchUnread && feedUnreadDirty ? "always" : false, + // DON'T refetch when the router is pop to previous page + refetchOnMount: fetchUnread && feedUnreadDirty && !history.isPop ? "always" : false, staleTime: // Force refetch unread entries when feed is dirty // HACK: disable refetch when the router is pop to previous page - fetchUnread && feedUnreadDirty && !history.isPop - ? 0 - : // Keep reduce data fetch logic - reduceRefetch - ? maxStaleTime - : defaultStaleTime, + history.isPop + ? Infinity + : fetchUnread && feedUnreadDirty + ? 0 + : // Keep reduce data fetch logic + reduceRefetch + ? maxStaleTime + : defaultStaleTime, }, ) } diff --git a/apps/renderer/src/store/entry/store.ts b/apps/renderer/src/store/entry/store.ts index d5eabd3774..7a710b3e2d 100644 --- a/apps/renderer/src/store/entry/store.ts +++ b/apps/renderer/src/store/entry/store.ts @@ -11,7 +11,7 @@ import { omitObjectUndefinedValue } from "@follow/utils/utils" import { isNil, merge, omit } from "es-toolkit/compat" import { produce } from "immer" -import { clearFeedUnreadDirty, setFeedUnreadDirty } from "~/atoms/feed" +import { clearAllFeedUnreadDirty, clearFeedUnreadDirty, setFeedUnreadDirty } from "~/atoms/feed" import { runTransactionInScope } from "~/database" import { apiClient } from "~/lib/api-fetch" import { getEntriesParams } from "~/lib/utils" @@ -147,7 +147,7 @@ class EntryActions { }) if (data.data) { - this.upsertMany(data.data, { isArchived }) + this.upsertMany(structuredClone(data.data), { isArchived }) } return data } @@ -170,6 +170,9 @@ class EntryActions { // Mark feed unread dirty, so re-fetch the unread data when view feed unread entires in the next time if (read === false) { + if (typeof params.view === "number" && !params.feedId) { + clearAllFeedUnreadDirty() + } if (params.feedId) { clearFeedUnreadDirty(params.feedId as string) } @@ -180,7 +183,7 @@ class EntryActions { } } if (data.data) { - this.upsertMany(data.data, { isArchived }) + this.upsertMany(structuredClone(data.data), { isArchived }) } return data }