From a00095df666e80fe17093488aa2535fe362bc58c Mon Sep 17 00:00:00 2001 From: "DESKTOP-I1T6TF3\\Q" <2291969160@qq.com> Date: Thu, 4 Jun 2026 15:13:03 +0800 Subject: [PATCH] Revert "fix(image): try fetching image as a blob directly first to avoid progressive rendering" This reverts commit 676c0f1af877ed73cfc2d2198691d545ee960efe. --- app/play/page.tsx | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/play/page.tsx b/app/play/page.tsx index cdb5dae..e920b8a 100644 --- a/app/play/page.tsx +++ b/app/play/page.tsx @@ -151,25 +151,28 @@ function proxiedImageUrl(originalUrl: string): string { async function fetchImageAsBlobUrl(url: string): Promise { if (url.startsWith("data:")) return url; - // Try to fetch as blob first (direct if CORS-enabled, or through proxy if configured) - const targetUrl = shouldProxy(url) ? proxiedImageUrl(url) : url; + // Direct path (default): warm the cache + decode, hand back the original + // URL. No fetch() — im.runware.ai has no CORS, so fetch().blob() would throw. + if (!shouldProxy(url)) { + await preloadImage(url); + return url; + } + + // Proxy path (opt-in): fetch through the Worker and materialize a blob: URL. + // On error / timeout fall back to the original URL so still tries + // (possible progressive paint — same as the direct path, never worse). const ctrl = new AbortController(); const timer = setTimeout(() => ctrl.abort(), IMAGE_PRELOAD_TIMEOUT_MS); try { - const r = await fetch(targetUrl, { signal: ctrl.signal }); - if (r.ok) { - const blob = await r.blob(); - return URL.createObjectURL(blob); - } - } catch (e) { - console.warn("Direct blob fetch failed (CORS or network), falling back to preload:", e); + const r = await fetch(proxiedImageUrl(url), { signal: ctrl.signal }); + if (!r.ok) return url; + const blob = await r.blob(); + return URL.createObjectURL(blob); + } catch { + return url; } finally { clearTimeout(timer); } - - // Fallback: warm the cache + decode, return the original CDN URL (may load progressively) - await preloadImage(url); - return url; } // Module-level cache so speculative prefetches and the eventual commit share