fix(web): topbar place Enter picks best match on /map instead of /search #1216

Merged
chris merged 1 commit from ux/topbar-place-enter-pick into main 2026-10-14 13:26:49 +02:00
Owner

Gap

On /map, typing a place and pressing Enter faster than the 300 ms suggestion debounce left no active suggestion row, so the form fell through to the plain /search media-results page — the wrong intent on the map page.

Behaviour after this PR

On /map (place search active), Enter with no active suggestion row:

  • Query >= 2 chars → treat as "pick the best match": await the search the debounce already scheduled (quiet loading status line; the existing request is reused, never duplicated — honouring the seq guard), then select the top-ranked result and fly. Enter-while-loading settles the in-flight/timed request first, then decides. Zero results → stay on /map with the quiet No matches status; never navigate to /search.
  • Query < 2 chars → unchanged plain /search submit.
  • Active suggestion row → unchanged (picks that row).
  • Post-pick is identical to a clicked pick: field shows the place name, list closes, focus stays in the input (reopen-after-pick / committedQuery semantics preserved).
  • ARIA stays consistent: aria-expanded true while waiting, aria-activedescendant null until rows exist, quiet status line only — no dialogs/toasts.

Mobile expanded field is identical (same component/handler). All other pages are unchanged — the component only renders when the page registers onPlaceSearchSelect.

Implementation

  • TopbarPlaceSuggestions.svelte: the debounce effect now records a pendingSearch entry ({ q, done, wake }) for the scheduled/in-flight run; effect cleanup wakes awaiters so a superseded search can never hang Enter. New settleQuery(q) awaits that entry (or runs the same seq-guarded search when the effect short-circuited on a committed query), pickBestMatch(q) settles then picks results[0]. runSearch tracks settledQuery so Enter only ever acts on rows it owns.
  • AppHeader.svelte: comments only, reflecting the wider Enter contract.

Tests — apps/web/tests/map-place-search.spec.ts (cold-boot gated)

  • New: 'copen' + Enter before results render (places/search mocked with a 1200 ms delay so the press reliably beats the response) → map flies to Copenhagen, URL stays /map, exactly one gazetteer request, focus stays in the input, ARIA transitions checked.
  • New: Enter on a zero-result query → stays on /map with the quiet no-match caption, no /search navigation.
  • Kept green: 1-char query + Enter → /search?q=o (unchanged); active-row Enter picks that row (existing reopen test); click pick; existing ARIA/quiet-status coverage.

Verification (apps/web)

  • npm run check — 0 errors
  • npm run test:unit — 32 files, 239 tests passed
  • npm run build — succeeded
  • npx playwright test tests/map-place-search.spec.ts tests/upload-status.spec.ts — 22/22 passed twice on consecutive cold boots (preview server killed between runs)
## Gap On /map, typing a place and pressing Enter **faster than the 300 ms suggestion debounce** left no active suggestion row, so the form fell through to the plain /search media-results page — the wrong intent on the map page. ## Behaviour after this PR On /map (place search active), Enter with **no active suggestion row**: - **Query >= 2 chars** → treat as "pick the best match": await the search the debounce already scheduled (quiet loading status line; the existing request is reused, never duplicated — honouring the seq guard), then select the top-ranked result and fly. **Enter-while-loading** settles the in-flight/timed request first, then decides. Zero results → stay on /map with the quiet *No matches* status; **never** navigate to /search. - **Query < 2 chars** → unchanged plain /search submit. - **Active suggestion row** → unchanged (picks that row). - Post-pick is identical to a clicked pick: field shows the place name, list closes, focus stays in the input (reopen-after-pick / committedQuery semantics preserved). - ARIA stays consistent: `aria-expanded` true while waiting, `aria-activedescendant` null until rows exist, quiet status line only — no dialogs/toasts. Mobile expanded field is identical (same component/handler). All other pages are unchanged — the component only renders when the page registers `onPlaceSearchSelect`. ## Implementation - `TopbarPlaceSuggestions.svelte`: the debounce effect now records a `pendingSearch` entry (`{ q, done, wake }`) for the scheduled/in-flight run; effect cleanup wakes awaiters so a superseded search can never hang Enter. New `settleQuery(q)` awaits that entry (or runs the same seq-guarded search when the effect short-circuited on a committed query), `pickBestMatch(q)` settles then picks `results[0]`. `runSearch` tracks `settledQuery` so Enter only ever acts on rows it owns. - `AppHeader.svelte`: comments only, reflecting the wider Enter contract. ## Tests — `apps/web/tests/map-place-search.spec.ts` (cold-boot gated) - **New**: 'copen' + Enter *before* results render (`places/search` mocked with a 1200 ms delay so the press reliably beats the response) → map flies to Copenhagen, URL stays /map, exactly **one** gazetteer request, focus stays in the input, ARIA transitions checked. - **New**: Enter on a zero-result query → stays on /map with the quiet no-match caption, no /search navigation. - **Kept green**: 1-char query + Enter → `/search?q=o` (unchanged); active-row Enter picks that row (existing reopen test); click pick; existing ARIA/quiet-status coverage. ## Verification (apps/web) - `npm run check` — 0 errors - `npm run test:unit` — 32 files, 239 tests passed - `npm run build` — succeeded - `npx playwright test tests/map-place-search.spec.ts tests/upload-status.spec.ts` — **22/22 passed twice on consecutive cold boots** (preview server killed between runs)
fix(web): topbar place Enter picks best match on /map instead of /search
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 4s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 13m20s
a4a45a2177
Pressing Enter faster than the 300 ms suggestion debounce left no active
row, so the form fell through to the media-search page — the wrong intent
on the map.

On /map (place search active), Enter with no active row and a query of 2+
characters now means "best match": it awaits the search the debounce
already scheduled (reusing the request — no duplicate, honouring the seq
guard; Enter-while-loading settles it first), then picks the top-ranked
result and flies. Zero results stay on /map with the quiet no-match
status — never a /search navigation. Queries below 2 characters keep the
plain media-search submit, active-row Enter is unchanged, and every other
page's header is untouched. The component only renders when the page
registers onPlaceSearchSelect, so the interception is map-scoped.

Tests (map-place-search.spec.ts, cold-boot gated):
- Enter before results render (delayed places/search) flies to
  Copenhagen, URL stays /map, exactly one gazetteer request
- Enter on a zero-result query stays on /map with the no-match caption
- 1-char query + Enter still navigates to /search?q=… (existing)
- active-row Enter still picks that row (existing)
chris merged commit bdf835333f into main 2026-10-14 13:26:49 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1216
No description provided.