Skip to content

Commit db91dbc

Browse files
committed
luci-static: fix race condition when probing features
follow-up to a2fce95 hasSystemFeature() inspects the cached result of probeSystemFeatures() which needs to have completed. Once all of the legacy (Lua) stuff is ready, this block runs: initDOM() { ... L.loaded = true; document.dispatchEvent(new CustomEvent('luci-loaded')); }, This commit now calls View.load() once system feature probing has completed, and LuCI itself has loaded. This ensures that the following load paradigm succeeds: return view.extend({ load() { return Promise.all([ ..., L.hasSystemFeature('x'), ]); }, ... The luci-loaded check prevents waiting when LuCI is already loaded (the common case after initial page load), but the listener handles the race condition where a View is instantiated before initDOM() completes. The flow: If L.loaded is true: initDOM() already ran --> skip waiting, proceed immediately. If L.loaded is false: initDOM() hasn't run yet --> add listener --> wait for it to complete. Signed-off-by: Paul Donald <newtwen+github@gmail.com>
1 parent 74d2192 commit db91dbc

File tree

1 file changed

+8
-10
lines changed
  • modules/luci-base/htdocs/luci-static/resources

1 file changed

+8
-10
lines changed

modules/luci-base/htdocs/luci-static/resources/luci.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,16 +1899,14 @@
18991899

19001900
DOM.content(vp, E('div', { 'class': 'spinning' }, _('Loading view…')));
19011901

1902-
return Promise.resolve(this.load())
1903-
.then(function (...args) {
1904-
if (L.loaded) {
1905-
return Promise.resolve(...args);
1906-
} else {
1907-
return new Promise(function (resolve) {
1908-
document.addEventListener('luci-loaded', resolve.bind(null, ...args), { once: true });
1909-
});
1910-
}
1911-
})
1902+
const ready = L.loaded
1903+
? Promise.resolve()
1904+
: new Promise((resolve) => {
1905+
document.addEventListener('luci-loaded', resolve, { once: true });
1906+
});
1907+
1908+
return ready
1909+
.then(LuCI.prototype.bind(this.load, this))
19121910
.then(LuCI.prototype.bind(this.render, this))
19131911
.then(LuCI.prototype.bind(function(nodes) {
19141912
const vp = document.getElementById('view');

0 commit comments

Comments
 (0)