Skip to content

feat(xref): move term autocomplete from client to server#511

Open
marcoscaceres wants to merge 5 commits into
mainfrom
feat/server-autocomplete
Open

feat(xref): move term autocomplete from client to server#511
marcoscaceres wants to merge 5 commits into
mainfrom
feat/server-autocomplete

Conversation

@marcoscaceres

Copy link
Copy Markdown
Collaborator

Summary

  • Adds GET /xref/meta/terms/search?q=<query>&limit=<n> endpoint
  • Binary search for prefix matches + linear scan infix fallback on a pre-sorted 22K terms array
  • Case-insensitive matching, original-case results, 24h cache
  • Client drops the 483KB terms download; autocomplete uses 150ms-debounced server fetch instead
  • Existing /xref/meta/terms endpoint unchanged (backward compatible)
  • 12 unit tests for the search logic

Closes #226

Test plan

  • pnpm run build passes
  • pnpm test passes (82 specs)
  • curl 'localhost:8000/xref/meta/terms/search?q=event&limit=5' returns JSON array
  • Load /xref in browser, verify autocomplete works with debounced server fetch
  • Verify initial page load no longer includes terms in the meta payload
  • GET /xref/meta/terms still returns the full array (backward compat)

marcoscaceres and others added 3 commits May 3, 2026 20:46
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>
Comment thread routes/xref/terms.get.ts Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/search endpoint with cached, case-insensitive term lookup over a prebuilt index.
  • Update the xref client to stop requesting the full terms payload 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.

Comment thread routes/xref/terms.get.ts Outdated
Comment thread static/xref/script.js
marcoscaceres and others added 2 commits May 3, 2026 21:08
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move autocomplete to server

3 participants