From a4a257f8e7b4be585b1fc0ba7cd1a221c5df8e9f Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Mon, 24 Mar 2025 16:40:17 -0400 Subject: [PATCH] adds a hard coded delay to drastically reduce theme picker jank --- docs/assets/scripts/theme-picker.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/assets/scripts/theme-picker.js b/docs/assets/scripts/theme-picker.js index e9220a235..b22a60414 100644 --- a/docs/assets/scripts/theme-picker.js +++ b/docs/assets/scripts/theme-picker.js @@ -4,9 +4,12 @@ export function domChange(fn, { behavior = 'smooth' } = {}) { document.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches; if (canUseViewTransitions && behavior === 'smooth') { - document.startViewTransition(fn); - } else { - fn(true); + const transition = document.startViewTransition(() => { + fn(true); + // Wait a brief delay before finishing the transition to prevent jumpiness + return new Promise(resolve => setTimeout(resolve, 200)); + }); + return transition; } }