(null);
+ // True once this visit has seen the download running. Only then is "your
+ // last download finished" worth showing; a revisit stays quiet (the "In
+ // library" button already says where the file is).
+ const [watchedDownload, setWatchedDownload] = useState(false);
// Server-side tasks outlive this page; re-attach to the newest one for this
// post so navigating away and back keeps the progress view.
@@ -186,6 +190,19 @@ export function OnlineDetail({ postId }: { postId: number }) {
const downloadStatus = downloadTask?.status;
const downloadActive =
downloadStatus === "pending" || downloadStatus === "downloading";
+ // Never render another post's task — this covers the single frame before the
+ // remount (DetailPage keys this component per post). A null post_id (older or
+ // hand-made tasks) stays visible rather than hiding a real download.
+ const downloadTaskMatchesPost =
+ !downloadTask ||
+ downloadTask.post_id === null ||
+ downloadTask.post_id === post?.id;
+
+ // Derived state (safe to set during render): remember that this visit saw
+ // the download running.
+ if (downloadActive && !watchedDownload) {
+ setWatchedDownload(true);
+ }
useEffect(() => {
if (!downloadStatus) return;
@@ -340,7 +357,8 @@ export function OnlineDetail({ postId }: { postId: number }) {
- {downloadTask &&
+ {downloadTaskMatchesPost &&
+ downloadTask &&
(downloadTask.status === "pending" ||
downloadTask.status === "downloading") ? (
@@ -372,7 +390,7 @@ export function OnlineDetail({ postId }: { postId: number }) {
cancel
- ) : downloadTask?.status === "complete" ? (
+ ) : downloadTaskMatchesPost && downloadTask?.status === "complete" ? (
Downloaded to the library
@@ -385,13 +403,13 @@ export function OnlineDetail({ postId }: { postId: number }) {
) : null}
- ) : downloadTask?.status === "cancelled" ? (
+ ) : downloadTaskMatchesPost && downloadTask?.status === "cancelled" ? (
Download cancelled.
- ) : downloadTask?.status === "error" ? (
+ ) : downloadTaskMatchesPost && downloadTask?.status === "error" ? (
{downloadTask.error || "Download failed."}
- ) : remoteFinishedTask && !downloadMutation.isPending ? (
+ ) : remoteFinishedTask && watchedDownload && !downloadMutation.isPending ? (
Your last download for this post finished