Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(image-card): fix React hooks rules violation

Louis Beaumontedccc6542a91
diff --git a/screenpipe-app-tauri/components/rewind/image-card.tsx b/screenpipe-app-tauri/components/rewind/image-card.tsx
index 6f1b68582..1b2697f51 100644
--- a/screenpipe-app-tauri/components/rewind/image-card.tsx
+++ b/screenpipe-app-tauri/components/rewind/image-card.tsx
@@ -16,6 +16,14 @@ const useImageWithRetry = (frameId: number) => {
const [hasError, setHasError] = useState(false);
const retryCount = useRef(0);
+ // Reset state when frameId changes
+ useEffect(() => {
+ setSrc(`http://localhost:3030/frames/${frameId}`);
+ setIsLoading(true);
+ setHasError(false);
+ retryCount.current = 0;
+ }, [frameId]);
+
const handleLoad = useCallback(() => {
setIsLoading(false);
setHasError(false);
@@ -234,6 +242,9 @@ export const MainImage = () => {
const currentFrame = searchResults[currentResultIndex];
+ // Call hook unconditionally (React rules of hooks)
+ const { src, isLoading, hasError, handleLoad, handleError } = useImageWithRetry(currentFrame?.frame_id ?? 0);
+
useEffect(() => {
const updateImageRect = () => {
if (imageRef.current) {
@@ -264,8 +275,6 @@ export const MainImage = () => {
);
}
- const { src, isLoading, hasError, handleLoad, handleError } = useImageWithRetry(currentFrame.frame_id);
-
return (
<div
ref={containerRef}