feat(xref): move term autocomplete from client to server#511
Open
marcoscaceres wants to merge 5 commits into
Open
feat(xref): move term autocomplete from client to server#511marcoscaceres wants to merge 5 commits into
marcoscaceres wants to merge 5 commits into
Conversation
Matches the pattern used by xref and caniuse update routes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add GET /xref/meta/terms/search?q=<query>&limit=<n> endpoint using binary search for prefix matches with infix fallback on a pre-sorted terms array. Case-insensitive matching, original-case results. Client no longer downloads 483KB of terms on page load. Instead, the autocomplete debounces at 150ms and fetches 15 suggestions per keystroke. The existing /xref/meta/terms endpoint is unchanged. Closes #226 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add .catch() and r.ok check to the client fetch so network errors and non-JSON responses degrade gracefully to an empty suggestion list. Add test verifying prefix matches precede infix-only matches. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR moves xref term autocomplete from the browser to the server by adding a dedicated term-search endpoint and updating the xref page to query it on demand instead of downloading the full term list up front. That fits the xref codebase’s existing split between server-side route handlers and a thin browser UI, and targets the payload-size problem described in #226.
Changes:
- Add a new
GET /xref/meta/terms/searchendpoint with cached, case-insensitive term lookup over a prebuilt index. - Update the xref client to stop requesting the full
termspayload and instead fetch debounced autocomplete suggestions from the new endpoint. - Add route-level tests for the new term-search behavior; also align one baseline background worker type import with the existing worker-queue pattern.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/routes/xref/terms.test.js | Adds unit tests covering new server-side xref term search behavior. |
| static/xref/script.js | Switches autocomplete from client-side Fuse search to debounced server fetches and trims initial metadata fetch. |
| routes/xref/terms.get.ts | Introduces the new xref term search endpoint and in-memory sorted term index. |
| routes/xref/index.ts | Wires the new /meta/terms/search route into the xref router. |
| routes/api/baseline/update.ts | Updates the worker module type import to match the existing typed background-task-queue pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Normalize req.query.q to a string when Express parses repeated ?q= params as an array. Remove the unused terms reference from the metadata object that would throw a ReferenceError. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Express parses repeated ?q= query parameters as arrays at runtime, which would crash searchTerms() since arrays lack toLowerCase(). Add tests verifying array params are normalized to the first element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /xref/meta/terms/search?q=<query>&limit=<n>endpoint/xref/meta/termsendpoint unchanged (backward compatible)Closes #226
Test plan
pnpm run buildpassespnpm testpasses (82 specs)curl 'localhost:8000/xref/meta/terms/search?q=event&limit=5'returns JSON array/xrefin browser, verify autocomplete works with debounced server fetchGET /xref/meta/termsstill returns the full array (backward compat)