diff --git a/admin/inertia/pages/settings/zim/remote-explorer.tsx b/admin/inertia/pages/settings/zim/remote-explorer.tsx index a19d9b3..2f90584 100644 --- a/admin/inertia/pages/settings/zim/remote-explorer.tsx +++ b/admin/inertia/pages/settings/zim/remote-explorer.tsx @@ -175,6 +175,26 @@ export default function ZimRemoteExplorer() { }, [data, downloads, localFiles]) const hasMore = useMemo(() => data?.pages[data.pages.length - 1]?.has_more || false, [data]) + // When a ZIM download drops off the polled downloads list it has completed (or been + // cancelled). The installed-files query (refetchOnWindowFocus is off) won't otherwise + // refresh, so a just-installed ZIM stays absent from `localFiles` and reappears in the + // accumulated remote pages as a ghost entry. Refresh it so the item is pruned. + const prevDownloadKeysRef = useRef>(new Set()) + useEffect(() => { + const currentKeys = new Set((downloads ?? []).map((d) => d.jobId)) + let anyRemoved = false + for (const key of prevDownloadKeysRef.current) { + if (!currentKeys.has(key)) { + anyRemoved = true + break + } + } + prevDownloadKeysRef.current = currentKeys + if (anyRemoved) { + queryClient.invalidateQueries({ queryKey: [ZIM_FILES_KEY] }) + } + }, [downloads, queryClient]) + const fetchOnBottomReached = useCallback( (parentRef?: HTMLDivElement | null) => { if (parentRef) {