fix(play): guard decode callback against stale img ref

Verify imgRef.current === el before firing onImageReady, so a
late-resolving decode from a prior <img> element cannot trigger
the gate prematurely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yuanzonghao
2026-06-13 11:51:15 +08:00
parent e3ee3547e5
commit a1b6848688
+2 -1
View File
@@ -413,7 +413,8 @@ export function PlayCanvas({
if (!onImageReady) return; if (!onImageReady) return;
const el = imgRef.current; const el = imgRef.current;
if (!el) { onImageReady(); return; } if (!el) { onImageReady(); return; }
el.decode().then(onImageReady, onImageReady); const notify = () => { if (imgRef.current === el) onImageReady(); };
el.decode().then(notify, notify);
}} }}
className={`block select-none animate-fade-in transition-opacity duration-700 ease-out ${ className={`block select-none animate-fade-in transition-opacity duration-700 ease-out ${
imageClickable ? "cursor-pointer" : interactive ? "cursor-default" : "cursor-wait" imageClickable ? "cursor-pointer" : interactive ? "cursor-default" : "cursor-wait"