From 18136d4eb57662a53f21bd77fb0f479b3b70dd43 Mon Sep 17 00:00:00 2001 From: ukimsanov Date: Thu, 23 Apr 2026 20:17:13 -0400 Subject: [PATCH] fix(shader-transitions): add inWindow guard to .catch fallback handler Address Vance's review on #456: the .catch handler was missing the same tl.time() window check that .then has. Late-rejecting captures (Safari + SVG-filter compositions) could fire gsap.to/fromTo on scenes the playhead already left, causing flash-to-black mid-scene. Wraps the CSS crossfade fallback in the same inWindow guard so stale catch handlers are no-ops, matching the .then behavior. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../shader-transitions/src/hyper-shader.ts | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/shader-transitions/src/hyper-shader.ts b/packages/shader-transitions/src/hyper-shader.ts index a6c0611e3e..30064fc0d7 100644 --- a/packages/shader-transitions/src/hyper-shader.ts +++ b/packages/shader-transitions/src/hyper-shader.ts @@ -318,17 +318,20 @@ export function init(config: HyperShaderConfig): GsapTimeline { // images, iframe sandbox restrictions, etc.) the old hard-cut // was jarring. A CSS crossfade is strictly better UX. console.warn("[HyperShader] Capture failed, CSS crossfade fallback:", e); - const fromEl = document.getElementById(fromId); - const toEl = document.getElementById(toId); - if (fromEl && toEl) { - gsap.to(fromEl, { opacity: 0, duration: dur, ease }); - gsap.fromTo(toEl, { opacity: 0 }, { opacity: 1, duration: dur, ease }); - } else { - // Last-resort hard cut if elements are somehow missing - document.querySelectorAll(".scene").forEach((s) => { - s.style.opacity = "0"; - }); - if (toEl) toEl.style.opacity = "1"; + const nowTime = tl.time(); + const inWindow = nowTime >= T && nowTime < T + dur; + if (inWindow) { + const fromEl = document.getElementById(fromId); + const toEl = document.getElementById(toId); + if (fromEl && toEl) { + gsap.to(fromEl, { opacity: 0, duration: dur, ease }); + gsap.fromTo(toEl, { opacity: 0 }, { opacity: 1, duration: dur, ease }); + } else { + document.querySelectorAll(".scene").forEach((s) => { + s.style.opacity = "0"; + }); + if (toEl) toEl.style.opacity = "1"; + } } if (wasPlaying) tl.play(); });