Commit ecdbe22e authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix JS intialization on commit page

When commit diffs are loaded async, we only delay JS initialization
of the diff. The other JS initialization do not depend on the diffs
to be present.
parent 1a7b8741
...@@ -18,20 +18,18 @@ import { __ } from '~/locale'; ...@@ -18,20 +18,18 @@ import { __ } from '~/locale';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const hasPerfBar = document.querySelector('.with-performance-bar'); const hasPerfBar = document.querySelector('.with-performance-bar');
const performanceHeight = hasPerfBar ? 35 : 0; const performanceHeight = hasPerfBar ? 35 : 0;
const filesContainer = $('.js-diffs-batch'); initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight + performanceHeight);
const initAfterPageLoad = () => {
new Diff();
new ZenMode(); new ZenMode();
new ShortcutsNavigation(); new ShortcutsNavigation();
new MiniPipelineGraph({ new MiniPipelineGraph({
container: '.js-commit-pipeline-graph', container: '.js-commit-pipeline-graph',
}).bindEvents(); }).bindEvents();
initNotes(); initNotes();
initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight + performanceHeight);
// eslint-disable-next-line no-jquery/no-load // eslint-disable-next-line no-jquery/no-load
$('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath); $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
fetchCommitMergeRequests(); fetchCommitMergeRequests();
};
const filesContainer = $('.js-diffs-batch');
if (filesContainer.length) { if (filesContainer.length) {
const batchPath = filesContainer.data('diffFilesPath'); const batchPath = filesContainer.data('diffFilesPath');
...@@ -42,12 +40,12 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -42,12 +40,12 @@ document.addEventListener('DOMContentLoaded', () => {
filesContainer.html($(data.html)); filesContainer.html($(data.html));
syntaxHighlight(filesContainer); syntaxHighlight(filesContainer);
handleLocationHash(); handleLocationHash();
initAfterPageLoad(); new Diff();
}) })
.catch(() => { .catch(() => {
flash(__('An error occurred while retrieving diff files')); flash(__('An error occurred while retrieving diff files'));
}); });
} else { } else {
initAfterPageLoad(); new Diff();
} }
}); });
...@@ -26,8 +26,6 @@ RSpec.describe 'Mini Pipeline Graph in Commit View', :js do ...@@ -26,8 +26,6 @@ RSpec.describe 'Mini Pipeline Graph in Commit View', :js do
build.run build.run
visit project_commit_path(project, project.commit.id) visit project_commit_path(project, project.commit.id)
wait_for_all_requests
expect(page).to have_selector('.mr-widget-pipeline-graph') expect(page).to have_selector('.mr-widget-pipeline-graph')
first('.mini-pipeline-graph-dropdown-toggle').click first('.mini-pipeline-graph-dropdown-toggle').click
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment