luci-base: don't render until luci-loaded is done
authorJames Haggerty <[email protected]>
Mon, 8 Apr 2024 02:37:42 +0000 (02:37 +0000)
committerPaul Donald <[email protected]>
Tue, 7 Oct 2025 14:16:51 +0000 (16:16 +0200)
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 <[email protected]>
modules/luci-base/htdocs/luci-static/resources/luci.js

index a1207f567c45dc8dcec478c6bdd407e824f0d17d..1a5eaa296c3ecb3891d5a8a768b4df6730a602ff 100644 (file)
                        DOM.content(vp, E('div', { 'class': 'spinning' }, _('Loading view…')));
 
                        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(function(nodes) {
                                        const vp = document.getElementById('view');
                initDOM() {
                        originalCBIInit();
                        Poll.start();
+                       L.loaded = true;
                        document.dispatchEvent(new CustomEvent('luci-loaded'));
                },
 
+               loaded: false,
+
                /**
                 * The `env` object holds environment settings used by LuCI, such
                 * as request timeouts, base URLs etc.