From ce0183579ae4a0d5f4b68da4508ea071021530e4 Mon Sep 17 00:00:00 2001 From: David Clark Date: Tue, 23 Jun 2026 21:35:41 -0400 Subject: [PATCH 1/2] search bar performance improvement - flush debounce on enter --- .../[campaignId]/campaign-events-modal.tsx | 15 +++++---------- apps/web/ui/shared/search-box.tsx | 8 ++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-modal.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-modal.tsx index 1f9d9215d4b..ca291abcc86 100644 --- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-modal.tsx +++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-events-modal.tsx @@ -7,7 +7,6 @@ import { buildUrl, fetcher } from "@dub/utils"; import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; import useSWR from "swr"; -import { useDebouncedCallback } from "use-debounce"; import { CampaignEvent, EventStatus } from "./campaign-events"; import { campaignEventsColumns } from "./campaign-events-columns"; @@ -33,12 +32,6 @@ export function CampaignEventsModal({ const [search, setSearch] = useState(""); const [debouncedSearch, setDebouncedSearch] = useState(""); - const debounced = useDebouncedCallback((value) => { - setDebouncedSearch(value); - // Reset pagination to page 1 when search changes - setPagination((prev) => ({ ...prev, pageIndex: 1 })); - }, 500); - const { data: events, error, @@ -121,9 +114,11 @@ export function CampaignEventsModal({
{ - setSearch(value); - debounced(value); + onChange={setSearch} + onChangeDebounced={(value) => { + setDebouncedSearch(value); + // Reset pagination to page 1 when search changes + setPagination((prev) => ({ ...prev, pageIndex: 1 })); }} placeholder="Search by partner name or email..." loading={isLoading && debouncedSearch.length > 0} diff --git a/apps/web/ui/shared/search-box.tsx b/apps/web/ui/shared/search-box.tsx index 505a1257569..572cfb059e9 100644 --- a/apps/web/ui/shared/search-box.tsx +++ b/apps/web/ui/shared/search-box.tsx @@ -91,11 +91,19 @@ export const SearchBox = forwardRef( onChange(e.target.value); debounced(e.target.value); }} + onKeyDown={(e) => { + // Commit the search immediately on Enter rather than waiting out the + // debounce. isComposing guards against firing mid-IME-composition. + if (e.key === "Enter" && !e.nativeEvent.isComposing) { + debounced.flush(); + } + }} autoCapitalize="none" /> {showClearButton && value.length > 0 && (