Commit 7d2691db authored by Denys Mishunov's avatar Denys Mishunov Committed by Olena Horal-Koretska

Improved Snippet view performance

- don't load Monaco on the view
- bootstrap Vue as soon as possible and not after DOM ready
- load only the required modules for the Vue view
parent fdb87c5e
import LineHighlighter from '~/line_highlighter';
import BlobViewer from '~/blob/viewer';
import ZenMode from '~/zen_mode';
import initNotes from '~/init_notes'; import initNotes from '~/init_notes';
import snippetEmbed from '~/snippet/snippet_embed';
import { SnippetShowInit } from '~/snippets';
import loadAwardsHandler from '~/awards_handler'; import loadAwardsHandler from '~/awards_handler';
document.addEventListener('DOMContentLoaded', () => { if (!gon.features.snippetsVue) {
if (!gon.features.snippetsVue) { const LineHighlighterModule = import('~/line_highlighter');
new LineHighlighter(); // eslint-disable-line no-new const BlobViewerModule = import('~/blob/viewer');
new BlobViewer(); // eslint-disable-line no-new const ZenModeModule = import('~/zen_mode');
initNotes(); const SnippetEmbedModule = import('~/snippet/snippet_embed');
new ZenMode(); // eslint-disable-line no-new
snippetEmbed(); Promise.all([LineHighlighterModule, BlobViewerModule, ZenModeModule, SnippetEmbedModule])
} else { .then(
SnippetShowInit(); ([
initNotes(); { default: LineHighlighter },
} { default: BlobViewer },
loadAwardsHandler(); { default: ZenMode },
}); { default: SnippetEmbed },
]) => {
new LineHighlighter(); // eslint-disable-line no-new
new BlobViewer(); // eslint-disable-line no-new
new ZenMode(); // eslint-disable-line no-new
SnippetEmbed();
},
)
.catch(() => {});
} else {
import('~/snippets')
.then(({ SnippetShowInit }) => {
SnippetShowInit();
})
.catch(() => {});
}
initNotes();
loadAwardsHandler();
...@@ -3,8 +3,6 @@ import VueApollo from 'vue-apollo'; ...@@ -3,8 +3,6 @@ import VueApollo from 'vue-apollo';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import SnippetsShow from './components/show.vue';
import SnippetsEdit from './components/edit.vue';
import { SNIPPET_LEVELS_MAP, SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants'; import { SNIPPET_LEVELS_MAP, SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -48,9 +46,17 @@ function appFactory(el, Component) { ...@@ -48,9 +46,17 @@ function appFactory(el, Component) {
} }
export const SnippetShowInit = () => { export const SnippetShowInit = () => {
appFactory(document.getElementById('js-snippet-view'), SnippetsShow); import('./components/show.vue')
.then(({ default: SnippetsShow }) => {
appFactory(document.getElementById('js-snippet-view'), SnippetsShow);
})
.catch(() => {});
}; };
export const SnippetEditInit = () => { export const SnippetEditInit = () => {
appFactory(document.getElementById('js-snippet-edit'), SnippetsEdit); import('./components/edit.vue')
.then(({ default: SnippetsEdit }) => {
appFactory(document.getElementById('js-snippet-edit'), SnippetsEdit);
})
.catch(() => {});
}; };
...@@ -5,6 +5,7 @@ import initSnippet from '~/snippet/snippet_bundle'; ...@@ -5,6 +5,7 @@ import initSnippet from '~/snippet/snippet_bundle';
jest.mock('~/snippet/snippet_bundle'); jest.mock('~/snippet/snippet_bundle');
jest.mock('~/snippets'); jest.mock('~/snippets');
jest.mock('~/gl_form');
describe('Snippet edit form initialization', () => { describe('Snippet edit form initialization', () => {
const setFF = flag => { const setFF = flag => {
......
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