fix: the Search Sources card loads its saved settings again
All checks were successful
Forgejo Docker Build / Root app tests (push) Successful in 45s
Forgejo Docker Build / Build Docker image (push) Successful in 17s
Forgejo Docker Build / End-to-end (browser) (push) Successful in 7s

PubMed read "Disabled" after every refresh while the database said true,
and the Test button reported the truth — so the card was showing its
defaults, not its settings.

The browser said why, once asked:

    [Admin] Settings load failed:
    ReferenceError: loadWebSearch is not defined

This file is a series of bare { } blocks, and a function declared in one
is not in scope in another. loadWebSearch lives in the block at 322 and
was called from the settings loader in the block at 42. Worse than not
running: the call sat inside that loader's .then(), so it threw and took
the rest of the handler with it.

It now loads itself on tabChanged, which is what every other block in
this file already does.

There is a comment at the top of loadAdmin saying loadOidcConfig cannot
be called from there for exactly this reason. Someone met this hazard
before; the web search call was added later without seeing it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dv6sqaY6Vq3ChZHMem3cnU
This commit is contained in:
Daniel 2026-09-13 02:12:17 +02:00
parent 1242b01286
commit 302736af70

View file

@ -85,7 +85,6 @@ function adminTabActive() {
if (el) el.textContent = stats.todayApiCalls !== undefined ? stats.todayApiCalls : '—';
updateRegStatus(settings.registrationEnabled !== false);
loadWebSearch();
})
.catch(function(err) { console.error('[Admin] Settings load failed:', err); });
}
@ -420,6 +419,19 @@ function adminTabActive() {
// Its own endpoints rather than the generic setter: the key is masked on read
// and a blank field means "keep what is there", so changing the provider does
// not silently wipe a working key.
//
// Loads itself on tabChanged, like every other block in this file. It used to
// be called from the settings loader in the block above, which cannot see it:
// this file is a series of bare { } blocks, and a function declared in one is
// not in scope in another. That call threw ReferenceError on every admin
// open, and because it sat inside the settings .then(), it took the rest of
// that handler down with it — so the card showed its defaults and PubMed read
// "Disabled" while the database said true.
document.addEventListener('tabChanged', function (e) {
if (e.detail && e.detail.tab === 'admin') loadWebSearch();
});
if (adminTabActive()) loadWebSearch();
function loadWebSearch() {
fetch('/api/admin/websearch', { headers: getAuthHeaders() })
.then(function(r) { return r.json(); })