Skip to content

Commit b4b9682

Browse files
Show 404 suggestions section even when empty
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
1 parent 4ad07ef commit b4b9682

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

app/components/errors.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function ErrorPage({
108108
) : null}
109109
<HeroSection {...resolvedHeroProps} />
110110

111-
{possibleMatches?.length ? (
111+
{possibleMatches ? (
112112
<PossibleMatchesSection
113113
matches={possibleMatches}
114114
query={possibleMatchesQuery}
@@ -194,7 +194,7 @@ function PossibleMatchesSection({
194194
))}
195195
</ul>
196196
<p className="mt-4 text-sm text-slate-500">
197-
{hasMatches ? 'None of these match? ' : 'No deterministic matches found. '}
197+
{hasMatches ? 'None of these match? ' : 'No close matches found. '}
198198
<a href={searchUrl} className="underlined">
199199
Try semantic search
200200
</a>

app/utils/not-found-suggestions.server.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,6 @@ export async function getNotFoundSuggestions({
472472
// Keep tests fast; this can walk the repo content tree.
473473
if (process.env.NODE_ENV === 'test') return null
474474
if (request.method.toUpperCase() !== 'GET') return null
475-
const accept = request.headers.get('accept') ?? ''
476-
const wantsHtml =
477-
accept.includes('text/html') || accept.includes('application/xhtml+xml')
478-
if (!wantsHtml) return null
479475

480476
const resolvedPathname = normalizePathname(
481477
typeof pathname === 'string' && pathname
@@ -519,12 +515,8 @@ export async function getNotFoundSuggestions({
519515
}
520516
}
521517

522-
if (!matches.length) return null
523-
const sorted = sortNotFoundMatches(matches, { priorities }).slice(
524-
0,
525-
safeLimit,
526-
)
527-
return sorted.length ? { query, matches: sorted } : null
518+
const sorted = sortNotFoundMatches(matches, { priorities }).slice(0, safeLimit)
519+
return { query, matches: sorted }
528520
} catch (error: unknown) {
529521
// 404 pages should never fail the request because suggestions failed.
530522
console.error('Deterministic 404 suggestions failed', error)

0 commit comments

Comments
 (0)