Load the feed regardless of a slow or failed agents or companies fetch

The init block awaited /api/agents and /api/companies, both of which
only dim hidden companies, draw the affinity control and pick the
score order, before ever calling loadFeed; a slow or failed one left
the feed blank for good behind a silent catch that returned early.

The feed's own request now goes out alongside them rather than after.
Agents and companies fill in and redraw what they touch (the rail,
the feed's dimming, the reader's affinity slot) whenever they land,
reloading the feed if the real agent turns out to differ from what it
first loaded with. The feed's own fetch failing gets an empty state
with a retry instead of the same silent blank.

Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet committed 2026-09-29 15:23:48 +02:00
1 parent 91596300e1
commit 4fb9e801f5
2 files changed
+67 -25

No files matched your search

+65 -25
View File
@@ -107,6 +107,7 @@
pushedReader: false, // we own a history entry, so closing is `history.back()`
summarising: null, // the uid whose summary is being waited for
listY: 0, // where the page was scrolled when the reader replaced the feed
feedError: false, // the feed's own fetch failed; the empty state offers a retry
};
const safeUrl = (u) => (/^https?:\/\//i.test(u || "") ? u : "");
@@ -201,11 +202,20 @@
try {
data = await api(`/api/roles?${params}`);
} catch (err) {
// An append failure leaves what is already on screen; a first load or
// a reload has nothing to show, so the empty state offers a retry
// rather than leaving the feed blank for good.
if (!append && request === feedRequest) {
state.feedError = true;
state.loaded = false;
renderFeed();
}
return;
} finally {
if (request === feedRequest) state.loading = false;
}
if (request !== feedRequest) return;
state.feedError = false;
const held = append ? state.items[state.selected]?.uid : state.readingUid;
state.total = data.total;
@@ -579,21 +589,29 @@
sync($("#roles-list"), state.items.map((role, i) => [role.uid, { role, i }]), makeRow, fillRow);
const empty = $("#feed-empty");
empty.hidden = !(state.loaded && !state.items.length);
empty.hidden = !((state.loaded || state.feedError) && !state.items.length);
if (!empty.hidden) {
const f = state.filter;
const filtered = state.q || f.tags.size || f.period !== "all" || !f.showRead
|| f.company.trim() || f.place.trim() || f.function || f.remote || f.judged;
empty.innerHTML = filtered
? `<h2>Nothing matches</h2>
<p>No open role fits these filters.
<button type="button" class="linky" data-clear>Clear them</button> and start again.</p>`
: `<h2>No roles yet</h2>
<p>Nothing has been pulled yet. <a href="/settings/sources#runs">Runs</a> starts one;
<a href="/settings/sources#job-boards">Job boards</a> and
<a href="/settings/sources#company-boards">Company boards</a> decide what it brings in.</p>`;
const clear = empty.querySelector("[data-clear]");
if (clear) clear.onclick = () => { state.q = ""; $("#search").value = ""; clearFilters(); };
if (state.feedError) {
empty.innerHTML = `<h2>Could not load the feed</h2>
<p>The server did not answer. <button type="button" class="linky" data-retry
>Try again</button>.</p>`;
const retry = empty.querySelector("[data-retry]");
if (retry) retry.onclick = () => loadFeed();
} else {
const f = state.filter;
const filtered = state.q || f.tags.size || f.period !== "all" || !f.showRead
|| f.company.trim() || f.place.trim() || f.function || f.remote || f.judged;
empty.innerHTML = filtered
? `<h2>Nothing matches</h2>
<p>No open role fits these filters.
<button type="button" class="linky" data-clear>Clear them</button> and start again.</p>`
: `<h2>No roles yet</h2>
<p>Nothing has been pulled yet. <a href="/settings/sources#runs">Runs</a> starts one;
<a href="/settings/sources#job-boards">Job boards</a> and
<a href="/settings/sources#company-boards">Company boards</a> decide what it brings in.</p>`;
const clear = empty.querySelector("[data-clear]");
if (clear) clear.onclick = () => { state.q = ""; $("#search").value = ""; clearFilters(); };
}
}
// The end of the list says which end it is: a list that has run out and
@@ -1092,19 +1110,41 @@
wire();
renderRail();
renderActive();
// The agent first: the companies, the feed and the counts are its.
try {
await Promise.all([loadTracked(), loadAgents()]);
chooseAgent();
await loadCompanies(state.filter.agent);
} catch (err) {
return;
}
renderRail();
renderActive();
loadFilters().catch(() => {});
// The feed is the page; agents and companies are enhancements that fill
// in when they arrive, not something it waits on — a slow or failed
// /api/agents or /api/companies must not leave it blank. Each one drawn
// here is greyed or missing until `enhance` lands, which is what "no
// agent" (renderAgent), an unjoined company (paintRow) and the tag row
// being empty already mean, so nothing here is a new state to handle.
const before = state.filter.agent;
const enhance = (async () => {
try {
await Promise.all([loadTracked(), loadAgents()]);
chooseAgent();
await loadCompanies(state.filter.agent);
} catch (err) {
return;
}
renderRail();
renderActive();
loadFilters().catch(() => {});
// The feed's first request went out with whatever agent `readUrl` had
// (often none): reload for the score and votes once the real one is
// known, and either way bring the reader's affinity control and judge
// buttons up to date, since `companies` was still empty when it first
// painted.
if (state.filter.agent !== before) reload();
else renderFeed();
if (state.readingUid) {
if (state.filter.agent !== before) refreshReader(state.readingUid);
else renderReader();
}
})();
route();
await loadFeed({ keep: was ? was.count : 0 });
if (was && !state.readingUid) window.scrollTo(0, was.y || 0);
await enhance;
});
})();
+2
View File
@@ -122,6 +122,8 @@ What was decided for roledesk and the one reason for each. The longer reasoning
**Each roledesk tab renders an empty shell; `static/roles.js` fills it and drives every action.** Roles, Applications, Agents and Companies extend the boilerplate's `base.html`; the server renders only select options (from `app.models`, `plugins.ats.FUNCTIONS` and `plugins.ats.HOSTS`, so they cannot drift from what the store and the plugin accept). One code path for "show this" beats a server-rendered first page plus a client re-render after every filter change.
**The feed loads whether or not its enhancements do.** `/api/agents` and `/api/companies` only dim hidden companies, draw the affinity control and pick the viewing agent's score order; the init block used to await both before ever calling `loadFeed`, so a slow or failed one left the feed blank for good behind a silent `catch (err) { return; }`. Now the feed's own request goes out alongside them rather than after, agents and companies fill in and redraw what they touch (the rail, the feed's dimming, the reader's affinity slot) whenever they land, and a feed already fetched with no agent known reloads once the real one is. A failed feed fetch of its own gets an empty state with a retry (`state.feedError`) instead of the same silent blank.
**`roles(company=, place=)` match a case-insensitive substring of what the board wrote.** The API's company and place fields are free text a person types, not a slug, so "Trade Republic" finds `trade-republic-bank` without knowing the key.
**A muted company is excluded in SQL, before `LIMIT`.** Filtering after `LIMIT` shipped first and showed nothing once Databricks' 884 freshly pulled roles filled the newest 200 rows and Databricks was muted.