⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
fix(mobile): link add flicker bug
daniel31x133800170328bf
diff --git a/apps/mobile/components/DashboardSection.tsx b/apps/mobile/components/DashboardSection.tsxindex 95f088db..11f81264 100644--- a/apps/mobile/components/DashboardSection.tsx+++ b/apps/mobile/components/DashboardSection.tsx@@ -21,6 +21,7 @@ import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types/globaimport LinkListing from "@/components/LinkListing";import { useColorScheme } from "nativewind";import { useRouter } from "expo-router";+import { hasOptimisticLink } from "@/lib/utils";// Don't use prisma client's DashboardSectionType, it'll crash in production (React Native)type DashboardSectionType =@@ -150,7 +151,10 @@ const DashboardSection: React.FC<DashboardSectionProps> = ({if (!dashboardData.isRefetching &&- links.some((e) => e.id && !e.preview)+ !hasOptimisticLink(links) &&+ links.some(+ (e) => typeof e.id === "number" && e.id > 0 && !e.preview+ )) {dashboardData.refetch();}@@ -233,7 +237,10 @@ const DashboardSection: React.FC<DashboardSectionProps> = ({if (!dashboardData.isRefetching &&- links.some((e) => e.id && !e.preview)+ !hasOptimisticLink(links) &&+ links.some(+ (e) => typeof e.id === "number" && e.id > 0 && !e.preview+ )) {dashboardData.refetch();}@@ -315,7 +322,10 @@ const DashboardSection: React.FC<DashboardSectionProps> = ({if (!dashboardData.isRefetching &&- links.some((e) => e.id && !e.preview)+ !hasOptimisticLink(links) &&+ links.some(+ (e) => typeof e.id === "number" && e.id > 0 && !e.preview+ )) {dashboardData.refetch();}diff --git a/apps/mobile/components/Links.tsx b/apps/mobile/components/Links.tsxindex 95ae3b16..33f80112 100644--- a/apps/mobile/components/Links.tsx+++ b/apps/mobile/components/Links.tsx@@ -13,6 +13,7 @@ import { rawTheme, ThemeName } from "@/lib/colors";import { useColorScheme } from "nativewind";import { useQueryClient } from "@tanstack/react-query";import { resetInfiniteQueryPagination } from "@linkwarden/router/lib";+import { hasOptimisticLink } from "@/lib/utils";const RenderItem = React.memo(({ item }: { item: LinkIncludingShortenedCollectionAndTags }) => {@@ -88,7 +89,11 @@ export default function Links({ links, data }: Props) {(e) => e.item) as LinkIncludingShortenedCollectionAndTags[];- if (!data.isRefetching && links.some((e) => e.id && !e.preview))+ if (+ !data.isRefetching &&+ !hasOptimisticLink(links) &&+ links.some((e) => typeof e.id === "number" && e.id > 0 && !e.preview)+ )data.refetch();}}viewabilityConfig={{ itemVisiblePercentThreshold: 50 }}diff --git a/apps/mobile/lib/utils.ts b/apps/mobile/lib/utils.tsnew file mode 100644index 00000000..4c4aa632--- /dev/null+++ b/apps/mobile/lib/utils.ts@@ -0,0 +1,11 @@+import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types/global";++/**+ * Optimistic (just-added) links carry a temporary negative id and only exist+ * in the local cache until the create mutation resolves. While one is present+ * we must avoid full-list refetches, which would replace the cache with a server snapshot+ * that doesn't include it yet, making it flash out and back in.+ */+export const hasOptimisticLink = (+ links: LinkIncludingShortenedCollectionAndTags[]+) => links.some((e) => typeof e.id === "number" && e.id < 0);