Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix: Infinite reload on project pin/unpin

Blue Mouse06a4f1cb6df5
diff --git a/web/app/pages/Dashboard/Dashboard.tsx b/web/app/pages/Dashboard/Dashboard.tsx
index 078df7c97..69d5c2504 100644
--- a/web/app/pages/Dashboard/Dashboard.tsx
+++ b/web/app/pages/Dashboard/Dashboard.tsx
@@ -10,7 +10,14 @@ import {
XIcon,
FolderPlusIcon,
} from '@phosphor-icons/react'
-import React, { useState, useEffect, useRef, useMemo, memo } from 'react'
+import React, {
+ useState,
+ useEffect,
+ useRef,
+ useMemo,
+ useCallback,
+ memo,
+} from 'react'
import { useTranslation } from 'react-i18next'
import {
useLoaderData,
@@ -275,9 +282,9 @@ const Dashboard = () => {
setNewProjectBeenSubmitted(false)
}
- const refetchProjects = () => {
+ const refetchProjects = useCallback(() => {
revalidator.revalidate()
- }
+ }, [revalidator])
// Update URL when debounced search changes
useEffect(() => {
diff --git a/web/app/pages/Dashboard/ProjectCard.tsx b/web/app/pages/Dashboard/ProjectCard.tsx
index 16d993272..328f0a540 100644
--- a/web/app/pages/Dashboard/ProjectCard.tsx
+++ b/web/app/pages/Dashboard/ProjectCard.tsx
@@ -9,7 +9,7 @@ import {
CaretUpIcon,
CaretDownIcon,
} from '@phosphor-icons/react'
-import React, { useState, useMemo, useCallback, useEffect } from 'react'
+import React, { useState, useMemo, useCallback, useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { Link, useFetcher, useNavigate } from 'react-router'
import { toast } from 'sonner'
@@ -175,11 +175,16 @@ export const ProjectCard = ({
setLocalIsPinned(isPinned)
}, [isPinned])
+ const processedFetcherDataRef = useRef<DashboardActionData | undefined>(
+ undefined,
+ )
+
// Handle fetcher responses
useEffect(() => {
- if (!fetcher.data) return
+ if (!fetcher.data || fetcher.data === processedFetcherDataRef.current)
+ return
+ processedFetcherDataRef.current = fetcher.data
- // Guard: only process responses for this specific project card
const submittedProjectId = fetcher.formData?.get('projectId')
const submittedShareId = fetcher.formData?.get('shareId')
const isForThisCard =