Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4726c43

Browse files
arunodatimneutkens
authored andcommitted
Scroll to the hash only if there's one after an error. (vercel#2224)
1 parent ad4ec55 commit 4726c43

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/app.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ class Container extends Component {
4444

4545
scrollToHash () {
4646
const { hash } = this.props
47+
if (!hash) return
48+
4749
const el = document.getElementById(hash)
48-
if (el) {
49-
// If we call scrollIntoView() in here without a setTimeout
50-
// it won't scroll properly.
51-
setTimeout(() => el.scrollIntoView(), 0)
52-
}
50+
if (!el) return
51+
52+
// If we call scrollIntoView() in here without a setTimeout
53+
// it won't scroll properly.
54+
setTimeout(() => el.scrollIntoView(), 0)
5355
}
5456

5557
shouldComponentUpdate (nextProps) {

0 commit comments

Comments
 (0)