luci-base: don't render until luci-loaded is done

Because the setupDOM/initDOM methods do strange things related
to the old lua server rendered templates
(like remove all the elements currently hidden by dependencies...),
we want to be sure that these have finished before the view
itself renders.

This also ensures that any caching (e.g. from probeSystemFeatures)
is finished before the view render.

This feels like a hacky fix, but it's not clear to me what the best
one is.

Signed-off-by: James Haggerty <james.haggerty@morsemicro.com>
This commit is contained in:
James Haggerty
2024-04-08 02:37:42 +00:00
committed by Paul Donald
parent 9924970dce
commit a2fce95248

View File

@@ -1893,6 +1893,15 @@
DOM.content(vp, E('div', { 'class': 'spinning' }, _('Loading view…'))); DOM.content(vp, E('div', { 'class': 'spinning' }, _('Loading view…')));
return Promise.resolve(this.load()) return Promise.resolve(this.load())
.then(function (...args) {
if (L.loaded) {
return Promise.resolve(...args);
} else {
return new Promise(function (resolve) {
document.addEventListener('luci-loaded', resolve.bind(null, ...args), { once: true });
});
}
})
.then(LuCI.prototype.bind(this.render, this)) .then(LuCI.prototype.bind(this.render, this))
.then(LuCI.prototype.bind(function(nodes) { .then(LuCI.prototype.bind(function(nodes) {
const vp = document.getElementById('view'); const vp = document.getElementById('view');
@@ -2688,9 +2697,12 @@
initDOM() { initDOM() {
originalCBIInit(); originalCBIInit();
Poll.start(); Poll.start();
L.loaded = true;
document.dispatchEvent(new CustomEvent('luci-loaded')); document.dispatchEvent(new CustomEvent('luci-loaded'));
}, },
loaded: false,
/** /**
* The `env` object holds environment settings used by LuCI, such * The `env` object holds environment settings used by LuCI, such
* as request timeouts, base URLs etc. * as request timeouts, base URLs etc.