Преглед на файлове

fix: switch theme at once on Safari, where the reveal flashed the glass

WebKit (Safari, and every browser on iOS, Chrome included) paints a view
transition's snapshots without backdrop blur, so the glass nav and cards
went clear for the length of the circular reveal and then snapped back.
WebKit browsers now switch the theme instantly; Chromium, whose
snapshots keep the blur, keeps the reveal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEPoSHwHCYMNpm2iKxY9hL
Claude преди 1 месец
родител
ревизия
eb1793b17c
променени са 1 файла, в които са добавени 16 реда и са изтрити 1 реда
  1. 16 1
      lib/theme-transition.ts

+ 16 - 1
lib/theme-transition.ts

@@ -8,6 +8,17 @@ type ViewTransitionDoc = Document & {
   startViewTransition?: (update: () => void) => { ready: Promise<void> };
 };
 
+/**
+ * WebKit (Safari, and every browser on iOS) paints view-transition snapshots
+ * without backdrop blur, so the glass nav and cards turned clear for the
+ * length of the reveal and flashed back. There the theme switches at once.
+ */
+const snapshotsDropGlass = () => {
+  const ua = navigator.userAgent;
+
+  return /AppleWebKit/.test(ua) && !/(Chrome|Chromium|Edg|OPR)\//.test(ua);
+};
+
 /**
  * Switches the theme with a circular reveal that grows from `origin`
  * (usually the button that was clicked). Falls back to an instant switch.
@@ -24,7 +35,11 @@ export function switchTheme(
     flushSync(() => setTheme(next));
   };
 
-  if (!doc.startViewTransition || prefersReducedMotion()) {
+  if (
+    !doc.startViewTransition ||
+    prefersReducedMotion() ||
+    snapshotsDropGlass()
+  ) {
     apply();
 
     return;