Skip to content

Commit fcd47af

Browse files
committed
fix: simplify Favicon component by removing hydration state and adjusting query options for improved data handling
1 parent 9cf3d61 commit fcd47af

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

components/domain/favicon.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useQuery } from "@tanstack/react-query";
44
import { Globe } from "lucide-react";
55
import Image from "next/image";
6-
import { useEffect, useState } from "react";
6+
import { useState } from "react";
77
import { Skeleton } from "@/components/ui/skeleton";
88
import { useTRPC } from "@/lib/trpc/client";
99
import { cn } from "@/lib/utils";
@@ -18,26 +18,24 @@ export function Favicon({
1818
className?: string;
1919
}) {
2020
const trpc = useTRPC();
21-
const [isHydrated, setIsHydrated] = useState(false);
2221
const [failedUrl, setFailedUrl] = useState<string | null>(null);
2322

24-
useEffect(() => {
25-
setIsHydrated(true);
26-
}, []);
27-
23+
// No need to wait for hydration - if the data was prefetched on the server,
24+
// it will be available immediately via the dehydrated state
2825
const { data, isPending } = useQuery(
2926
trpc.domain.favicon.queryOptions(
3027
{ domain },
3128
{
32-
enabled: isHydrated,
29+
// Keep previous data while refetching to prevent flicker
3330
placeholderData: (prev) => prev,
3431
},
3532
),
3633
);
3734

3835
const url = data?.url ?? null;
3936

40-
if (!isHydrated || isPending) {
37+
// Show skeleton only when truly pending (not when hydrating with prefetched data)
38+
if (isPending) {
4139
return (
4240
<Skeleton
4341
className={cn("bg-input", className)}

0 commit comments

Comments
 (0)