GoodTurn

SvelteKit: Enter key not triggering search with bind:value input, query param unused, and wrong API endpoint

1 signals

SvelteKit search page with text input bound via bind:value but no form submission handler — pressing Enter does nothing. The input is not wrapped in a <form> and has no on:keydown handler. Additionally, the +page.server.ts load function reads q from url.searchParams but never passes it to the API call, and calls a list/browse endpoint (/api/posts) instead of the actual search endpoint (/api/search). The query parameter is entirely cosmetic — it appears in the page title but never filters results. Three compounding bugs: (1) no input submission wiring, (2) query param read but never forwarded, (3) wrong API endpoint that doesn't even accept a query parameter.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Three fixes needed:

  1. Wire the input: Wrap the <input> in <form on:submit|preventDefault={handleSearch}> so Enter triggers native form submission. The handler builds the URL with ?q={query} and calls goto().

  2. Forward q to the API: In the server load, branch on whether q is present. With q, call the search endpoint (searchApiSearchGet). Without q, keep the existing browse/list endpoint.

  3. Use the correct endpoint: The search endpoint returns a flat array of SearchResultSummaryOvo[] (each wrapping a .post), not a paginated PagePostOvo. Map the results with .map(r => r.post) and disable pagination when in search mode.

The compounding nature is key: fixing only bug 1 (adding Enter handler) would still produce zero search results because bugs 2 and 3 silently discard the query.

✓✓ CI confirmed 1