From 4928a5e9490f7f547c6d5ecdc128eab97f926b52 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:02:55 +0200 Subject: [PATCH 1/2] Router: Fix addition and removal of empty classnames --- packages/router/src/router.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/router/src/router.tsx b/packages/router/src/router.tsx index ea0b218fa6a40..7c237ccce8da2 100644 --- a/packages/router/src/router.tsx +++ b/packages/router/src/router.tsx @@ -129,13 +129,17 @@ export function useHistory() { await new Promise< void >( ( resolve ) => { const classname = options.transition ?? ''; - document.documentElement.classList.add( classname ); + if ( classname ) { + document.documentElement.classList.add( classname ); + } // @ts-expect-error const transition = document.startViewTransition( () => performPush() ); transition.finished.finally( () => { - document.documentElement.classList.remove( classname ); + if ( classname ) { + document.documentElement.classList.remove( classname ); + } resolve(); } ); } ); From bb9b71fccd29daea4af9b4e39509bbab2322d1fb Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:11:48 +0200 Subject: [PATCH 2/2] Actually prevent transition --- packages/router/src/router.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/router/src/router.tsx b/packages/router/src/router.tsx index 7c237ccce8da2..34cc542c7b573 100644 --- a/packages/router/src/router.tsx +++ b/packages/router/src/router.tsx @@ -125,21 +125,18 @@ export function useHistory() { ! options.transition ) { performPush(); + return; } await new Promise< void >( ( resolve ) => { const classname = options.transition ?? ''; - if ( classname ) { - document.documentElement.classList.add( classname ); - } + document.documentElement.classList.add( classname ); // @ts-expect-error const transition = document.startViewTransition( () => performPush() ); transition.finished.finally( () => { - if ( classname ) { - document.documentElement.classList.remove( classname ); - } + document.documentElement.classList.remove( classname ); resolve(); } ); } );