Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/kitchen-sink/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export default function Home() {
>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [hasSearched, setHasSearched] = useState(false);

async function handleSearch(e: React.FormEvent) {
e.preventDefault();
if (!query.trim()) return;

setError(null);
setLoading(true);
setHasSearched(true);
try {
const res = await fetch(
`/api/search?q=${encodeURIComponent(query)}&fuzzy=true`,
Expand Down Expand Up @@ -86,7 +88,7 @@ export default function Home() {
<p style={{ color: "red", marginTop: 12 }}>{error}</p>
)}

{results.length === 0 && query.trim() && !loading && !error && (
{results.length === 0 && hasSearched && !loading && !error && (
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard empty-state message when query is blank

Removing the query.trim() check makes the empty-state render for an empty input after any prior no-result search, because hasSearched stays true and results stays empty. In that flow, clearing the field shows No results found for '', which is misleading and regresses prior behavior where blank queries suppressed the message.

Useful? React with 👍 / 👎.

<p style={{ color: "#888", marginTop: 12 }}>No results found for &apos;{query}&apos;</p>
)}

Expand Down
Loading