Skip to content

Commit a334994

Browse files
authored
CMS editor async load fix (#8140)
Loading editor.js doesn't block the rest of the page's content loading anymore
1 parent 8312474 commit a334994

File tree

3 files changed

+162
-151
lines changed

3 files changed

+162
-151
lines changed

ydb/core/cms/ui/configs_dispatcher_main.js

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var createEditor;
1+
var createEditorPromise = new $.Deferred();
22

33
var codeMirror;
44
var codeMirrorResolved;
@@ -7,9 +7,12 @@ function replaceWithEditor(selector) {
77
var container = $(selector);
88
var value = container.text();
99
container.text("");
10-
var editor = createEditor(container.get(0), true, 1068)
11-
editor.setValue(value);
12-
return editor;
10+
var editorPromise = createEditorPromise.then(function(createEditor) {
11+
var editor = createEditor(container.get(0), true, 1068)
12+
editor.setValue(value);
13+
return editor;
14+
});
15+
return editorPromise;
1316
}
1417

1518
function main() {
@@ -22,63 +25,66 @@ function main() {
2225
}
2326
});
2427

25-
codeMirror = replaceWithEditor("#yaml-config-item");
26-
codeMirror.trigger('fold', 'editor.foldLevel2');
27-
28-
$("#fold-yaml-config").click(function() {
28+
replaceWithEditor("#yaml-config-item").then(function(codeMirror) {
2929
codeMirror.trigger('fold', 'editor.foldLevel2');
30+
31+
$("#fold-yaml-config").click(function() {
32+
codeMirror.trigger('fold', 'editor.foldLevel2');
33+
});
34+
35+
$("#unfold-yaml-config").click(function() {
36+
codeMirror.trigger('fold', 'editor.unfoldAll');
37+
});
38+
39+
$("#copy-yaml-config").click(function() {
40+
copyToClipboard(codeMirror.getValue());
41+
});
3042
});
3143

32-
$("#unfold-yaml-config").click(function() {
33-
codeMirror.trigger('fold', 'editor.unfoldAll');
34-
});
35-
36-
$("#copy-yaml-config").click(function() {
37-
copyToClipboard(codeMirror.getValue());
38-
});
39-
40-
codeMirrorResolved = replaceWithEditor("#resolved-yaml-config-item");
41-
codeMirrorResolved.trigger('fold', 'editor.foldLevel1');
42-
43-
$("#fold-resolved-yaml-config").click(function() {
44+
replaceWithEditor("#resolved-yaml-config-item").then(function(codeMirrorResolved) {
4445
codeMirrorResolved.trigger('fold', 'editor.foldLevel1');
45-
});
46-
47-
$("#unfold-resolved-yaml-config").click(function() {
48-
codeMirrorResolved.trigger('fold', 'editor.unfoldAll');
49-
});
50-
51-
$("#copy-resolved-yaml-config").click(function() {
52-
copyToClipboard(codeMirrorResolved.getValue());
46+
47+
$("#fold-resolved-yaml-config").click(function() {
48+
codeMirrorResolved.trigger('fold', 'editor.foldLevel1');
49+
});
50+
51+
$("#unfold-resolved-yaml-config").click(function() {
52+
codeMirrorResolved.trigger('fold', 'editor.unfoldAll');
53+
});
54+
55+
$("#copy-resolved-yaml-config").click(function() {
56+
copyToClipboard(codeMirrorResolved.getValue());
57+
});
5358
});
5459

5560
$("#host-ref").text("YDB Developer UI - " + window.location.hostname);
5661

5762
$(".yaml-config-item").each(function() {
58-
let editor = replaceWithEditor(this);
59-
60-
$(this).parent().find('.fold-yaml-config').click(function() {
61-
editor.trigger('fold', 'editor.foldLevel2');
62-
});
63-
64-
$(this).parent().find('.unfold-yaml-config').click(function() {
65-
editor.trigger('fold', 'editor.unfoldAll');
66-
});
67-
68-
$(this).parent().find('.copy-yaml-config').click(function() {
69-
copyToClipboard(editor.getValue());
63+
replaceWithEditor(this).then(function(editor) {
64+
$(this).parent().find('.fold-yaml-config').click(function() {
65+
editor.trigger('fold', 'editor.foldLevel2');
66+
});
67+
68+
$(this).parent().find('.unfold-yaml-config').click(function() {
69+
editor.trigger('fold', 'editor.unfoldAll');
70+
});
71+
72+
$(this).parent().find('.copy-yaml-config').click(function() {
73+
copyToClipboard(editor.getValue());
74+
});
7075
});
7176
});
7277
}
7378

7479
let run = () => {
7580
require.config({
7681
urlArgs: "v=0.27.0.2",
77-
paths: { vs: "../cms/ext/monaco-editor/vs" }
82+
paths: { vs: "../cms/ext/monaco-editor/vs" },
83+
waitSeconds: 60 // Since editor is quite large
7884
});
7985

8086
require(["vs/editor/editor.main"], function () {
81-
createEditor = (container, readOnly, width) => {
87+
createEditorPromise.resolve((container, readOnly, width) => {
8288
var editor;
8389
container.style.border = '1px solid #eee';
8490
container.style.borderRadius = '8px';
@@ -112,7 +118,7 @@ let run = () => {
112118
editor.onDidContentSizeChange(updateHeight);
113119
updateHeight();
114120
return editor;
115-
}
121+
});
116122

117123
$(document).ready(main);
118124
});

ydb/core/cms/ui/main.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ requirejs.config({
22
baseUrl: 'js/lib',
33
paths: {
44
jquery: 'ext/jquery.min'
5-
}
5+
},
6+
waitSeconds: 60 // Since editor is quite large
67
});
78

8-
var createEditor;
9+
var createEditorPromise = new $.Deferred();
910

1011
let run = () => {
1112
require.config({
@@ -14,7 +15,7 @@ let run = () => {
1415
});
1516

1617
require(["vs/editor/editor.main"], function () {
17-
createEditor = (container, readOnly, width) => {
18+
createEditorPromise.resolve((container, readOnly, width) => {
1819
var editor;
1920
container.style.border = '1px solid #eee';
2021
container.style.borderRadius = '8px';
@@ -48,7 +49,7 @@ let run = () => {
4849
editor.onDidContentSizeChange(updateHeight);
4950
updateHeight();
5051
return editor;
51-
}
52+
});
5253

5354
$(document).ready(main);
5455
});

0 commit comments

Comments
 (0)