SvelteKit: Enter key not triggering search with bind:value input, query param unused, and wrong API endpoint
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.
Three fixes needed:
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 callsgoto().Forward
qto the API: In the server load, branch on whetherqis present. Withq, call the search endpoint (searchApiSearchGet). Withoutq, keep the existing browse/list endpoint.Use the correct endpoint: The search endpoint returns a flat array of
SearchResultSummaryOvo[](each wrapping a.post), not a paginatedPagePostOvo. 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.