Skip to content

Fixed Filters on Search Result page - #23

Merged
damianlegawiec merged 1 commit into
mainfrom
fix/search-result-filtering
Feb 17, 2026
Merged

Fixed Filters on Search Result page#23
damianlegawiec merged 1 commit into
mainfrom
fix/search-result-filtering

Conversation

@damianlegawiec

@damianlegawiec damianlegawiec commented Feb 17, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved filter behavior to properly scope to the active search query, ensuring filtered results align with search terms and update dynamically when the search changes.

@coderabbitai

coderabbitai Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

A single hook was modified to scope filter fetches to the active search query by augmenting filter parameters with q[multi_search] when a search query is present. Dependency arrays were updated to ensure filters and products refetch when the search query changes.

Changes

Cohort / File(s) Summary
Filter Search Scoping
src/hooks/useProductListing.ts
Modified filter fetch to augment parameters with search query scope when searchQuery is present. Updated effect dependencies to include searchQuery, ensuring filters and products refetch synchronously with search query changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A whisker of wisdom in params we weave,
Search queries dance, filters now believe,
Dependencies aligned, the hook now sees clear,
Scoped to the query, the filters appear!
With a hop and a bound, this logic is sound.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fixed Filters on Search Result page' directly describes the main change: fixing filter functionality on the search results page by scoping filters to the search query.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/search-result-filtering

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/hooks/useProductListing.ts (1)

130-134: Consider resetting activeFilters when searchQuery changes.

Now that filters are correctly scoped to the search query, stale activeFilters (e.g. option values selected for a previous search) will persist across search query changes. This could produce empty or incorrect results when a user types a new search term while filters from the old search are still applied.

A lightweight fix would be to reset filters inside this effect:

Suggested approach
   useEffect(() => {
     if (storeLoading) return;
-    loadProducts(activeFilters, searchQuery);
+    const resetFilters: ActiveFilters = { optionValues: [] };
+    filtersRef.current = resetFilters;
+    setActiveFilters(resetFilters);
+    loadProducts(resetFilters, searchQuery);
     // eslint-disable-next-line react-hooks/exhaustive-deps
   }, [storeLoading, searchQuery]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useProductListing.ts` around lines 130 - 134, The effect that runs
on searchQuery change (useEffect watching [storeLoading, searchQuery]) should
reset activeFilters before calling loadProducts to avoid stale filters; modify
the effect to call the filter-resetter (e.g., setActiveFilters([]) or
resetActiveFilters()) when searchQuery changes and storeLoading is false, then
call loadProducts(activeFilters, searchQuery) (or pass the cleared filters
explicitly) so loadProducts uses the fresh filter state; ensure you use the
existing activeFilters and setter names from this hook.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/hooks/useProductListing.ts`:
- Around line 130-134: The effect that runs on searchQuery change (useEffect
watching [storeLoading, searchQuery]) should reset activeFilters before calling
loadProducts to avoid stale filters; modify the effect to call the
filter-resetter (e.g., setActiveFilters([]) or resetActiveFilters()) when
searchQuery changes and storeLoading is false, then call
loadProducts(activeFilters, searchQuery) (or pass the cleared filters
explicitly) so loadProducts uses the fresh filter state; ensure you use the
existing activeFilters and setter names from this hook.

@damianlegawiec
damianlegawiec merged commit f95fc5c into main Feb 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant