Просмотр исходного кода

fix: update the cursor label right after a click

The label only changed when the mouse moved, so after flipping the
avatar it kept saying "Meet Bert" while Bert was showing. It is read
again once the clicked element has re-rendered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEPoSHwHCYMNpm2iKxY9hL
Claude 1 месяц назад
Родитель
Сommit
1d18edf7c5
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      components/glass/cursor-lens.tsx

+ 11 - 0
components/glass/cursor-lens.tsx

@@ -55,6 +55,7 @@ function LensLayer() {
     let frame = 0;
     let frame = 0;
     let currentMode: Mode = "none";
     let currentMode: Mode = "none";
     let currentLabel = "";
     let currentLabel = "";
+    let last: PointerEvent | null = null;
 
 
     const tick = () => {
     const tick = () => {
       frame = 0;
       frame = 0;
@@ -78,6 +79,7 @@ function LensLayer() {
 
 
     const onMove = (e: PointerEvent) => {
     const onMove = (e: PointerEvent) => {
       if (e.pointerType !== "mouse") return;
       if (e.pointerType !== "mouse") return;
+      last = e;
       target.x = e.clientX;
       target.x = e.clientX;
       target.y = e.clientY;
       target.y = e.clientY;
       const el = (e.target as Element | null)?.closest?.(
       const el = (e.target as Element | null)?.closest?.(
@@ -109,8 +111,16 @@ function LensLayer() {
       currentLabel = "";
       currentLabel = "";
       setMode("none");
       setMode("none");
     };
     };
+    // A click can change what the thing under the cursor does (Meet Bert →
+    // Back to Eric), so read its label again once it has re-rendered.
+    const onClick = () => {
+      requestAnimationFrame(() => {
+        if (last && currentMode !== "none") onMove(last);
+      });
+    };
 
 
     window.addEventListener("pointermove", onMove, { passive: true });
     window.addEventListener("pointermove", onMove, { passive: true });
+    window.addEventListener("click", onClick, { passive: true });
     window.addEventListener("scroll", onLeave, { passive: true });
     window.addEventListener("scroll", onLeave, { passive: true });
     document.documentElement.addEventListener("pointerleave", onLeave);
     document.documentElement.addEventListener("pointerleave", onLeave);
     window.addEventListener("blur", onLeave);
     window.addEventListener("blur", onLeave);
@@ -118,6 +128,7 @@ function LensLayer() {
     return () => {
     return () => {
       cancelAnimationFrame(frame);
       cancelAnimationFrame(frame);
       window.removeEventListener("pointermove", onMove);
       window.removeEventListener("pointermove", onMove);
+      window.removeEventListener("click", onClick);
       window.removeEventListener("scroll", onLeave);
       window.removeEventListener("scroll", onLeave);
       document.documentElement.removeEventListener("pointerleave", onLeave);
       document.documentElement.removeEventListener("pointerleave", onLeave);
       window.removeEventListener("blur", onLeave);
       window.removeEventListener("blur", onLeave);