keep cancelled outline and search asks free during the Nominatim probe

Recheck the caller's signal right after the capability probe on every path, so an ask cleared while the probe is pending starts no outline or last-resort search request, whether the probe says configured, unknown or not configured.
This commit is contained in:
manjunath committed 2026-10-30 23:27:17 +05:30
1 parent f32ab5446b
commit 3824b4ebfc
4 files changed
+69 -7

No files matched your search

+6 -5
View File
@@ -80,11 +80,12 @@ export function createDefaultPlaceSearch({
createGoogleGeocoder({
async request(query, { bias, signal }) {
// The app's own route says up front when Nominatim is off.
if (
nominatimConfigured &&
(await nominatimConfigured()) === false
)
return null;
const capability = nominatimConfigured
? await nominatimConfigured()
: null;
// A search cancelled during the probe starts no request.
signal?.throwIfAborted();
if (capability === false) return null;
const params = new URLSearchParams({ q: query });
if (bias) params.set('bounds', bias);
return fetchImpl(
+28
View File
@@ -53,3 +53,31 @@ test('the last-resort route is skipped when the server reports Nominatim unconfi
const on = await run(true);
assert.ok(on.includes('/api/geocode'), on.join(','));
});
test('a search cancelled while the Nominatim probe is pending starts no last-resort request', async () => {
let release;
const held = new Promise((resolve) => {
release = resolve;
});
const asked = [];
const controller = new AbortController();
const search = createDefaultPlaceSearch({
endpoints: { photon: null },
fetchImpl: async (url) => {
const path = new URL(String(url), 'http://local.test').pathname;
asked.push(path);
if (path === '/api/geocode/status') {
controller.abort();
await held;
return Response.json({ configured: true });
}
return Response.json({ status: 'ZERO_RESULTS', results: [] });
},
});
const pending = search.geocode('nowhere-cancelled', {
signal: controller.signal,
});
release();
await pending.catch(() => null);
assert.ok(!asked.includes('/api/geocode'), asked.join(','));
});