feat: Frontend Search with Client-side Index#1
Conversation
- Add dual deployment to test and production environments - Add wrangler.toml.prod for production config - Trigger on main branch push
There was a problem hiding this comment.
Pull request overview
This pull request implements a significant architectural change by migrating the search functionality from a backend API to a client-side implementation using pre-built compressed indexes. The main goal is to enable faster, offline-capable search without requiring backend infrastructure.
Changes:
- Added client-side search using compressed gzip indexes with the
pakolibrary for decompression - Replaced server-side search API calls with local index loading and filtering
- Updated ES module import syntax from
asserttowithfor JSON imports - Added Cloudflare Wrangler configuration files for deployment
- Modified GitHub Actions workflow to deploy to both production and test Cloudflare Pages environments
Reviewed changes
Copilot reviewed 7 out of 22 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
components/search/useClientSearch.ts |
New React hook implementing client-side search with index loading, caching, and filtering logic |
app/search/page.tsx |
Simplified search page component to use the new client-side search hook instead of API calls |
package.json & package-lock.json & yarn.lock |
Added pako v2.1.0 dependency for gzip decompression |
scripts/rss.mjs |
Updated JSON import syntax from assert to with (ES modules import attributes) |
wrangler.toml & wrangler.toml.prod |
New Cloudflare Wrangler configuration files for test and production deployments |
.github/workflows/cf-pages-deploy.yml |
Updated workflow to deploy to both production and test Cloudflare Pages environments |
public/search-index/repo-*.json.gz |
Binary compressed search index files (not reviewed in detail as they are data files) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Restore URL update with router.push() - Restore tsindex.org banner - Restore page title 条目检索 - Restore complete initialValues for SearchForm - Restore Suspense boundary - Keep frontend search logic
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add all 10 domains to REPO_INDEXES - Add IndexDocument interface instead of any - Fix performance: check limit before inner loop - Add RESULT_LIMIT constant - Remove duplicate url/link (keep url only) - Use environment variable for account_id - Throw error to UI instead of just console - Improve Chinese search support - Fix URL update with router.push - Keep initialValues for all fields
- Deploy to transchinese-test on pull requests - Deploy to transchinese-org on main branch push - Separate jobs for preview and production
- Add lib/clientSearch.ts for client-side search - Replace API call with clientSearch() in page.tsx - Keep all original UI and functionality - Remove useClientSearch.ts hook (replaced by lib/clientSearch)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 23 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const file = REPO_INDEXES[domain] | ||
| if (!file) return null | ||
| try { | ||
| const res = await fetch(file) |
There was a problem hiding this comment.
loadIndex does not check res.ok before inflating; a 404/500 response body will be passed to pako.inflate and then JSON.parse, producing confusing errors. Add an if (!res.ok) branch (and ideally include status/url in the error) before reading/decompressing.
| const res = await fetch(file) | |
| const res = await fetch(file) | |
| if (!res.ok) { | |
| console.error( | |
| 'Failed to fetch search index', | |
| { domain, file, status: res.status, statusText: res.statusText } | |
| ) | |
| return null | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add workflow_dispatch support for deploy-preview - Remove continue-on-error to show real failures - Restore account_id in wrangler.toml.prod
- Remove ENDFILE (empty file) - Remove EOF (empty file) - Remove search-index.json.gz (duplicate, already in public/search-index/)
变更
优势
测试
待办