Skip to content
Snippets Groups Projects
Commit 7ad68523 authored by Douwe Maan's avatar Douwe Maan
Browse files

Merge branch 'rs-mr-tabs-scroll' into 'master'

Prevent a JS error in MergeRequestTabs

When `window.location.hash` is pointing to a note, e.g. `#note_1234`,
`scrollToElement` would throw an error because a selector such as
`.commits #note_1234` doesn't exist, so `offset()` returned `undefined`.

This error would prevent subsequent calls from running, which caused the
loading spinner to never be hidden.

Now we ensure the selector returns a valid element before trying to
scroll to it.

This is the proper fix for !1553.

See merge request !1597
parents 976400c1 fc0d9274
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
@@ -68,8 +68,8 @@ class @MergeRequestTabs
Loading
@@ -68,8 +68,8 @@ class @MergeRequestTabs
   
scrollToElement: (container) -> scrollToElement: (container) ->
if window.location.hash if window.location.hash
top = $(container + " " + window.location.hash).offset().top $el = $("#{container} #{window.location.hash}")
$('body').scrollTo(top) $('body').scrollTo($el.offset().top) if $el.length
   
# Activate a tab based on the current action # Activate a tab based on the current action
activateTab: (action) -> activateTab: (action) ->
Loading
@@ -127,7 +127,7 @@ class @MergeRequestTabs
Loading
@@ -127,7 +127,7 @@ class @MergeRequestTabs
document.getElementById('commits').innerHTML = data.html document.getElementById('commits').innerHTML = data.html
$('.js-timeago').timeago() $('.js-timeago').timeago()
@commitsLoaded = true @commitsLoaded = true
@scrollToElement(".commits") @scrollToElement("#commits")
   
loadDiff: (source) -> loadDiff: (source) ->
return if @diffsLoaded return if @diffsLoaded
Loading
@@ -137,7 +137,7 @@ class @MergeRequestTabs
Loading
@@ -137,7 +137,7 @@ class @MergeRequestTabs
success: (data) => success: (data) =>
document.getElementById('diffs').innerHTML = data.html document.getElementById('diffs').innerHTML = data.html
@diffsLoaded = true @diffsLoaded = true
@scrollToElement(".diffs") @scrollToElement("#diffs")
   
# Show or hide the loading spinner # Show or hide the loading spinner
# #
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment