Skip to content

Commit 98729ce

Browse files
committed
fix: resolve global search crashes and re-enable search bar
1 parent 25927e5 commit 98729ce

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

web/load.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ const run = async (url, branch, arch) => {
2929
*/
3030
const familyMap = {};
3131

32-
const resp = await fetch(url).then((res) => res.json());
32+
const res = await fetch(url);
33+
34+
if (!res.ok) {
35+
console.warn(`⚠️ Skipping ${branch}-${arch}: ${res.status} ${res.statusText}`);
36+
return;
37+
}
38+
39+
const resp = await res.json();
3340

3441
resp.forEach((data) => {
3542
response.push(data);

web/src/components/global-search.tsx

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,9 @@ export function GlobalSearch() {
117117
}, [open]);
118118

119119
const renderVirtualItems = React.useCallback(() => {
120-
return results.map((item, i) => {
121-
return (
122-
<div
123-
key={i}
124-
style={{
125-
//position: 'absolute',
126-
top: 0,
127-
left: 0,
128-
width: "100%",
129-
//height: `${virtualRow.size}px`,
130-
//transform: `translateY(${virtualRow.start}px)`,
131-
}}
132-
>
133-
<SearchResultItem item={item} onCopy={handleCopy} />
134-
</div>
135-
);
136-
});
120+
return results.map((item) => (
121+
<SearchResultItem key={`${item.pkg_name}#${item.pkg_id}#${item.source}`} item={item} onCopy={handleCopy} />
122+
));
137123
}, [results, handleCopy]);
138124

139125
const SearchButton = React.useMemo(
@@ -182,21 +168,12 @@ export function GlobalSearch() {
182168
<div className="flex items-center justify-center p-8 text-muted-foreground">
183169
Start typing to search packages...
184170
</div>
185-
) : (
171+
) : (
186172
<>
187173
<CommandEmpty>No results found.</CommandEmpty>
188174
{results.length > 0 && (
189-
<CommandGroup>
190-
<div
191-
style={{
192-
height: `40vh`,
193-
width: "100%",
194-
position: "relative",
195-
}}
196-
className="flex flex-col overflow-hidden overflow-y-scroll"
197-
>
198-
{renderVirtualItems()}
199-
</div>
175+
<CommandGroup className="max-h-[40vh] overflow-y-auto">
176+
{renderVirtualItems()}
200177
</CommandGroup>
201178
)}
202179
</>

web/src/hooks/use-search.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ export function useSearch(
2121
return;
2222
}
2323

24-
const searchResults = searchIndex.search(searchTerm, {
25-
prefix: true,
26-
fuzzy: true,
27-
});
24+
try {
25+
const searchResults = searchIndex.search(searchTerm, {
26+
prefix: true,
27+
fuzzy: true,
28+
});
2829

29-
setResults(
30-
searchResults.map((result) => result as unknown as SearchResult),
31-
);
30+
setResults(
31+
searchResults.map((result) => ({
32+
pkg_name: result.pkg_name as string,
33+
pkg_id: result.pkg_id as string,
34+
source: result.source as string,
35+
url: result.url as string,
36+
})),
37+
);
38+
} catch (error) {
39+
console.error("Search failed:", error);
40+
setResults([]);
41+
}
3242
}, [searchTerm, searchIndex, isLoading]);
3343

3444
return results;

web/src/layouts/Layout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { GlobalSearch } from "@/components/global-search";
2929
>
3030
</div>
3131
<div class="flex flex-row items-center gap-2">
32-
<!-- <GlobalSearch client:load /> -->
32+
<GlobalSearch client:load />
3333
<SocialLink client:load />
3434
<ModeToggle client:load />
3535
</div>

0 commit comments

Comments
 (0)