Skip to content

Commit e466776

Browse files
committed
Revert "fix: auto-save assets from store layer to survive tab switches"
This reverts commit 2decf2d.
1 parent 2decf2d commit e466776

3 files changed

Lines changed: 2 additions & 89 deletions

File tree

src/components/playground/BatchOutputGrid.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
detectAssetType,
2323
generateDownloadFilename,
2424
} from "@/stores/assetsStore";
25-
import { storeSavedPredictionIds } from "@/stores/playgroundStore";
2625
import { toast } from "@/hooks/useToast";
2726
import { cn } from "@/lib/utils";
2827
import type { BatchResult, BatchQueueItem } from "@/types/batch";
@@ -195,11 +194,9 @@ export function BatchOutputGrid({
195194
if (autoSavedIndexesRef.current.has(result.index)) continue;
196195
if (result.error || result.outputs.length === 0) continue;
197196

198-
// Skip if store-level auto-save already handled this prediction
199197
if (
200198
result.prediction?.id &&
201-
(storeSavedPredictionIds.has(result.prediction.id) ||
202-
hasAssetForPrediction(result.prediction.id))
199+
hasAssetForPrediction(result.prediction.id)
203200
) {
204201
autoSavedIndexesRef.current.add(result.index);
205202
setSavedIndexes((prev) => new Set(prev).add(result.index));

src/components/playground/OutputDisplay.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
detectAssetType,
77
generateDownloadFilename,
88
} from "@/stores/assetsStore";
9-
import { storeSavedPredictionIds } from "@/stores/playgroundStore";
109
import { Button } from "@/components/ui/button";
1110
import { Badge } from "@/components/ui/badge";
1211
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
@@ -135,7 +134,7 @@ export function OutputDisplay({
135134
const [gameEndedWithResults, setGameEndedWithResults] = useState(false);
136135
const prevOutputsLengthRef = useRef(0);
137136

138-
const { settings, loadSettings, saveAsset, hasAssetForPrediction } = useAssetsStore();
137+
const { settings, loadSettings, saveAsset } = useAssetsStore();
139138

140139
// Build list of media outputs for fullscreen navigation
141140
const mediaOutputs = useMemo(() => {
@@ -239,18 +238,6 @@ export function OutputDisplay({
239238
if (!settings.autoSaveAssets || !modelId || outputs.length === 0) return;
240239
if (!prediction?.id) return;
241240

242-
// Skip if store-level auto-save already handled this prediction
243-
if (storeSavedPredictionIds.has(prediction.id) || hasAssetForPrediction(prediction.id)) {
244-
// Mark all outputs as saved so the UI shows the correct state
245-
for (let i = 0; i < outputs.length; i++) {
246-
const output = outputs[i];
247-
if (typeof output === "string" && detectAssetType(output)) {
248-
setSavedIndexes((prev) => new Set(prev).add(i));
249-
}
250-
}
251-
return;
252-
}
253-
254241
// Find outputs not yet auto-saved
255242
const unsaved: { output: string; index: number }[] = [];
256243
for (let i = 0; i < outputs.length; i++) {
@@ -316,7 +303,6 @@ export function OutputDisplay({
316303
modelId,
317304
settings.autoSaveAssets,
318305
saveAsset,
319-
hasAssetForPrediction,
320306
t,
321307
]);
322308

src/stores/playgroundStore.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,6 @@ import type { BatchConfig, BatchState, BatchResult } from "@/types/batch";
1111
import { DEFAULT_BATCH_CONFIG } from "@/types/batch";
1212
import { persistentStorage } from "@/lib/storage";
1313
import { isImageUrl, isVideoUrl } from "@/lib/mediaUtils";
14-
import {
15-
useAssetsStore,
16-
detectAssetType,
17-
} from "@/stores/assetsStore";
18-
19-
/* ── Store-level auto-save to My Assets ───────────────────────────────── */
20-
21-
/**
22-
* Track prediction IDs that are currently being auto-saved (or already saved)
23-
* from the store layer. Shared between autoSaveToAssets and OutputDisplay
24-
* to prevent duplicate saves when both fire concurrently.
25-
*/
26-
export const storeSavedPredictionIds = new Set<string>();
27-
28-
/**
29-
* Auto-save prediction outputs to My Assets from the store layer.
30-
* This runs immediately when a prediction completes, regardless of which
31-
* tab is currently active — fixing the bug where switching tabs during
32-
* generation caused the OutputDisplay useEffect to miss the save.
33-
* Fire-and-forget; errors are logged but never thrown.
34-
*/
35-
function autoSaveToAssets(
36-
outputs: (string | Record<string, unknown>)[],
37-
modelId: string,
38-
predictionId: string | undefined,
39-
): void {
40-
if (!predictionId) return;
41-
if (storeSavedPredictionIds.has(predictionId)) return;
42-
43-
const { settings, saveAsset, hasAssetForPrediction } =
44-
useAssetsStore.getState();
45-
if (!settings.autoSaveAssets) return;
46-
if (hasAssetForPrediction(predictionId)) return;
47-
48-
// Mark immediately to prevent concurrent duplicate from OutputDisplay
49-
storeSavedPredictionIds.add(predictionId);
50-
51-
const unsaved: { output: string; index: number }[] = [];
52-
for (let i = 0; i < outputs.length; i++) {
53-
const output = outputs[i];
54-
if (typeof output !== "string") continue;
55-
if (output.startsWith("local-asset://")) continue;
56-
const assetType = detectAssetType(output);
57-
if (!assetType) continue;
58-
unsaved.push({ output, index: i });
59-
}
60-
if (unsaved.length === 0) return;
61-
62-
// Fire-and-forget — save each output
63-
(async () => {
64-
for (const { output, index } of unsaved) {
65-
try {
66-
await saveAsset(output, detectAssetType(output)!, {
67-
modelId,
68-
predictionId,
69-
originalUrl: output,
70-
resultIndex: index,
71-
});
72-
} catch (err) {
73-
console.error("[playgroundStore] auto-save asset failed:", err);
74-
}
75-
}
76-
})();
77-
}
7814

7915
/* ── Playground session persistence ───────────────────────────────────── */
8016

@@ -643,9 +579,6 @@ export const usePlaygroundStore = create<PlaygroundState>((set, get) => ({
643579
: tab,
644580
),
645581
}));
646-
647-
// Auto-save outputs to My Assets from store layer (tab-switch safe)
648-
autoSaveToAssets(outputs, selectedModel.model_id, result.id);
649582
} catch (error) {
650583
// Don't show error for user-initiated abort
651584
const isAbort =
@@ -912,9 +845,6 @@ export const usePlaygroundStore = create<PlaygroundState>((set, get) => ({
912845
: tab,
913846
),
914847
}));
915-
916-
// Auto-save outputs to My Assets from store layer (tab-switch safe)
917-
autoSaveToAssets(batchOutputs, selectedModel.model_id, result.id);
918848
} catch (error) {
919849
// Skip state updates for aborted requests
920850
const isAbort =

0 commit comments

Comments
 (0)