Skip to content

Commit 0aee8b5

Browse files
Merge pull request #441 from lightning-js/fix/undefined-focus
Fixed timing issue where routerview would sometimes try to focus the …
2 parents 49d4208 + a3d130f commit 0aee8b5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/components/RouterView.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import Component from '../component.js'
1919
import Router from '../router/router.js'
2020
import symbols from '../lib/symbols.js'
21+
import Focus from '../focus.js'
2122

2223
let hashchangeHandler = null
2324

@@ -44,7 +45,9 @@ export default () =>
4445
window.removeEventListener('hashchange', hashchangeHandler, false)
4546
},
4647
focus() {
47-
this.activeView && this.activeView.$focus()
48+
if (this.activeView && Focus.get() === this) {
49+
this.activeView.$focus()
50+
}
4851
},
4952
},
5053
input: {

src/router/router.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ export const navigate = async function () {
337337
// keep reference to the previous focus for storing in cache
338338
previousFocus = Focus.get()
339339

340+
const children = this[symbols.children]
341+
this.activeView = children[children.length - 1]
342+
340343
// set focus to the view that we're routing to
341344
focus ? focus.$focus() : /** @type {BlitsComponent} */ (view).$focus()
342345

@@ -380,8 +383,6 @@ export const navigate = async function () {
380383
await setOrAnimate(holder, route.transition.in, shouldAnimate)
381384
}
382385
}
383-
const children = this[symbols.children]
384-
this.activeView = children[children.length - 1]
385386
} else {
386387
Log.error(`Route ${hash} not found`)
387388
const routerHooks = this.parent[symbols.routerHooks]

0 commit comments

Comments
 (0)