From a3d130fd1bfa2bdd4fc083af4d9231c197a208be Mon Sep 17 00:00:00 2001 From: Michiel van der Geest Date: Tue, 5 Aug 2025 22:25:07 +0200 Subject: [PATCH] Fixed timing issue where routerview would sometimes try to focus the previous active page. --- src/components/RouterView.js | 5 ++++- src/router/router.js | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/RouterView.js b/src/components/RouterView.js index 296e099a..f6a3d97a 100644 --- a/src/components/RouterView.js +++ b/src/components/RouterView.js @@ -18,6 +18,7 @@ import Component from '../component.js' import Router from '../router/router.js' import symbols from '../lib/symbols.js' +import Focus from '../focus.js' let hashchangeHandler = null @@ -44,7 +45,9 @@ export default () => window.removeEventListener('hashchange', hashchangeHandler, false) }, focus() { - this.activeView && this.activeView.$focus() + if (this.activeView && Focus.get() === this) { + this.activeView.$focus() + } }, }, input: { diff --git a/src/router/router.js b/src/router/router.js index 871e1d17..3e7c0a9c 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -337,6 +337,9 @@ export const navigate = async function () { // keep reference to the previous focus for storing in cache previousFocus = Focus.get() + const children = this[symbols.children] + this.activeView = children[children.length - 1] + // set focus to the view that we're routing to focus ? focus.$focus() : /** @type {BlitsComponent} */ (view).$focus() @@ -380,8 +383,6 @@ export const navigate = async function () { await setOrAnimate(holder, route.transition.in, shouldAnimate) } } - const children = this[symbols.children] - this.activeView = children[children.length - 1] } else { Log.error(`Route ${hash} not found`) const routerHooks = this.parent[symbols.routerHooks]