Skip to content

fix: remove invalid setDebouncedSearch call in clearAll#198

Merged
kunalverma2512 merged 1 commit into
kunalverma2512:mainfrom
ShreyaSinghal22:fix/clear-all-debounce-crash
Jun 15, 2026
Merged

fix: remove invalid setDebouncedSearch call in clearAll#198
kunalverma2512 merged 1 commit into
kunalverma2512:mainfrom
ShreyaSinghal22:fix/clear-all-debounce-crash

Conversation

@ShreyaSinghal22

@ShreyaSinghal22 ShreyaSinghal22 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

📌 Pull Request Summary

🔗 Related Issue

Closes #161


📝 Description

Fixed a ReferenceError crash that occurred when clicking the "Clear All"
or "Clear All Filters" button on the Practice Page. The page was becoming
completely unresponsive to filter clearing.

Changes Made

  • Removed invalid setDebouncedSearch("") call from clearAll() in PracticePage.jsx

Motivation

The useDebounce hook returns only a debounced read-only value — it never
exposes a setter. Calling setDebouncedSearch("") caused JavaScript to throw
a ReferenceError immediately, which halted execution and prevented all
the reset logic below it (setSelectedTags, setRatingIdx, setSortBy,
setPage) from running. Removing this one invalid line is sufficient —
debouncedSearch automatically follows searchQuery after the 300ms
debounce timer.


🚀 Type of Change

  • Bug Fix

🧪 Testing

Verification

  • Tested Locally
  • Existing Tests Passed
  • New Tests Added
  • No Testing Required

Test Details

  • Navigated to /practice page
  • Typed a search query and applied tag/rating filters
  • Clicked "Clear All" chip → all filters reset, zero console errors ✅
  • Clicked "Clear All Filters" in the empty-results state → works correctly ✅
  • Verified normal search box typing → debounce behavior unaffected ✅
  • Checked DevTools Console → no ReferenceError present ✅

📸 Screenshots / Demo (If Applicable)


✅ Checklist

  • I have read and followed the contribution guidelines.
  • I have self-reviewed my changes.
  • My changes are limited to the scope of this issue.
  • Documentation has been updated where necessary.
  • No unnecessary files or unrelated changes have been included.
  • The related issue has been linked correctly.
  • All applicable testing and validation steps have been completed.

📚 Additional Notes

Two buttons both call clearAll() and were both broken by this bug:

  • The inline "Clear All" chip
  • The "Clear All Filters" button in the empty-results state
    Both are fixed by this single change. No regression to debounce behaviour
    during normal typing. No backend changes required.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the filter clearing functionality to properly reset all filter controls including search, tags, rating filters, sort order, and pagination to their default states.

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@ShreyaSinghal22 is attempting to deploy a commit to the Kunal Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

🎉 Welcome to CodeLens — Thank You for Your Contribution!

Hey @ShreyaSinghal22! 👋

We are genuinely excited to have you here. Every single PR — big or small — makes CodeLens better, and yours is no exception. Take a moment to review the checklist below to help us merge your work quickly and smoothly.

✅ Before Requesting a Review

  • Keep code clean, readable, and consistent with the existing codebase
  • Avoid unrelated or unnecessary file changes
  • Make sure the UI is fully responsive across all device sizes
  • Attach screenshots or a short screen recording for any UI changes
  • Resolve all merge conflicts before marking the PR as ready
  • Do not submit AI-generated, copy-pasted, or low-effort implementations

💬 Join Our Community Channel — This is Mandatory

Being part of our communication channel is compulsory for all contributors, not optional.

📡 Join the CodeLens Matrix Channel

Why join? This is where all important announcements, PR review updates, contribution discussions, and maintainer decisions happen in real time. Contributors who are not in the channel regularly miss critical context and updates, which often leads to duplicated or misaligned work. Staying connected here is what keeps the community strong and your contributions impactful.


We are rooting for you! If you have any questions, drop them in the channel or comment right here on this PR. Let's build something great together. 🚀✨

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eaf0adf0-5bc7-4b13-b976-ad6319194e9a

📥 Commits

Reviewing files that changed from the base of the PR and between 45268d8 and f07ab7b.

📒 Files selected for processing (1)
  • frontend/src/pages/PracticePage.jsx
💤 Files with no reviewable changes (1)
  • frontend/src/pages/PracticePage.jsx

📝 Walkthrough

Walkthrough

Removes one invalid line from the clearAll handler in PracticePage.jsx: the call to setDebouncedSearch(""), which referenced an undefined setter and caused a ReferenceError crash whenever either "Clear All" button was clicked. The remaining reset calls (setSearchQuery, setSelectedTags, setRatingIdx, setSortBy, pagination) are unchanged.

Changes

Fix clearAll crash on Practice Page

Layer / File(s) Summary
Remove invalid setDebouncedSearch call from clearAll
frontend/src/pages/PracticePage.jsx
Deletes the setDebouncedSearch("") line that was crashing with ReferenceError: setDebouncedSearch is not defined. The debouncedSearch value derives automatically from searchQuery via useDebounce, so no setter exists or is needed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A bunny pressed "Clear All" one day,
But a ghost setter got in the way! 🐇
setDebouncedSearch — never born,
Left the filters crumpled, torn.
One line removed, the crash is gone,
And the filters hop merrily on! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing an invalid setDebouncedSearch call from the clearAll function.
Description check ✅ Passed The description comprehensively follows the template with all major sections completed: related issue link, clear problem explanation, specific changes, motivation, type of change, testing details, and checklist items marked.
Linked Issues check ✅ Passed The PR fully addresses issue #161 requirements: removes the invalid setDebouncedSearch call, allows all reset operations to execute, and maintains debounce behavior during normal typing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #161. Only one line was removed from PracticePage.jsx, with no unrelated modifications or scope creep detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@kunalverma2512

Copy link
Copy Markdown
Owner

@coderabbitai please check whether work done in this PR is good to go and is ready to merge ?
make sure that its professionally everything is written and is compatible with whole codebase and especially nearby codes , files
Give me detailed and insane , honest reasoning about the work and whatever needed more to make things better if required

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== PracticePage.jsx full content ==="
fd "PracticePage.jsx" --exec cat {}

echo ""
echo "=== useDebounce hook ==="
fd -i "useDebounce" --exec cat {}

echo ""
echo "=== Search for setDebouncedSearch across entire codebase ==="
rg -rn "setDebouncedSearch" --type jsx --type js --type tsx --type ts

echo ""
echo "=== Search for debouncedSearch usage ==="
rg -rn "debouncedSearch" 

echo ""
echo "=== clearAll function references across codebase ==="
rg -rn "clearAll" 

echo ""
echo "=== PR diff via GitHub CLI ==="
gh pr view 198 --repo kunalverma2512/CodeLens --json files,body,title,state,additions,deletions

echo ""
echo "=== PR diff ==="
gh pr diff 198 --repo kunalverma2512/CodeLens

Length of output: 34812


🏁 Script executed:

#!/bin/bash
echo "=== Directory structure of frontend/src/pages ==="
fd . frontend/src/pages --type f

echo ""
echo "=== Directory structure of frontend/src/hooks ==="
fd . frontend/src/hooks --type f

echo ""
echo "=== Frontend package.json ==="
fd "package.json" --max-depth 3 --exec cat {} \; -x echo "---FILE: {}"

Length of output: 3199



@kunalverma2512 Here is a detailed, honest assessment of this PR:


✅ Verdict: The Fix is Correct and Safe to Merge

The change is a single-line removal that resolves a genuine, reproducible ReferenceError. Here is the full technical breakdown.


🔍 Root Cause Analysis

The useDebounce hook (frontend/src/hooks/useDebounce.js) returns only the debounced scalar value — no setter:

export function useDebounce(value, delay) {
  const [debouncedValue, setDebouncedValue] = useState(value);
  useEffect(() => {
    const handler = setTimeout(() => setDebouncedValue(value), delay);
    return () => clearTimeout(handler);
  }, [value, delay]);
  return debouncedValue; // ← scalar only, no [value, setter] tuple
}

PracticePage.jsx consumes it as:

const debouncedSearch = useDebounce(searchQuery, 300);

There is no setDebouncedSearch declared anywhere in the file or the codebase. The removed line was calling a function that does not exist, causing JavaScript to throw immediately and short-circuit all the subsequent reset calls (setSelectedTags, setRatingIdx, setSortBy, setPage).


✅ Is the Fix Sufficient?

Yes, completely. When setSearchQuery("") is called, the useDebounce effect fires after 300ms and internally updates debouncedValue to "". There is also a dedicated useEffect that resets the page when debouncedSearch changes:

useEffect(() => {
  setPage(1);
}, [debouncedSearch]);

So pagination is doubly covered — both by the clearAll call to setPage(1) and by the debounce effect. Everything is clean.


⚠️ Pre-existing Minor Observations (Not Introduced by This PR)

These are not blockers, but are worth knowing for future work:

  1. 300ms chip flicker after Clear AllhasFilters is computed using debouncedSearch (not searchQuery):

    const hasFilters = debouncedSearch || selectedTags.length > 0 || ...

    When "Clear All" is clicked, searchQuery is immediately "" but debouncedSearch trails by ~300ms. This means the active filter chips section (Active: "foo") stays visible briefly before disappearing. To fix this cosmetically, hasFilters could use searchQuery instead:

    const hasFilters = searchQuery || selectedTags.length > 0 || ratingIdx !== 0 || sortBy !== "rating-asc";

    This is a UX polish item, not a bug.

  2. clearAll is not wrapped in useCallback — Currently clearAll is recreated on every render. Since it is only attached to onClick handlers within the same component (not passed as a prop), this has no real-world perf impact. Fine as-is.

  3. No unit testsfrontend/src/hooks/useDebounce.js and PracticePage.jsx have zero test coverage. The PR checklist correctly marks this as unchecked. Adding a test for useDebounce would be a good follow-up.

  4. Missing screenshot in PR template — The "Screenshots / Demo" section of the PR description is empty. Not a functional issue, but screenshots or a screen recording would strengthen the review evidence.


📋 PR Quality Assessment

Aspect Assessment
Fix correctness ✅ Correct
Fix completeness ✅ Sufficient
Scope discipline ✅ Minimal, no unrelated changes
PR title ✅ Follows conventional commits (fix:)
PR description ✅ Technically accurate, professionally written
Issue linkage ✅ Closes #161 correctly
Testing ✅ Manual testing described; no automated tests (pre-existing gap)
Breaking changes ✅ None

🏁 Summary

The PR correctly identifies and eliminates the one invalid line causing a ReferenceError crash on the Practice Page. The useDebounce contract is respected, the debounce behavior for normal typing is unaffected, and all filter-reset state setters now execute without interruption. The codebase compatibility is fully maintained — no other files are impacted.

This is ready to merge. The pre-existing items above are good candidates for a follow-up polish PR if desired.

🐇✨

@kunalverma2512

Copy link
Copy Markdown
Owner

@coderabbitai Please make a new issue for what you said about first point you said in pre existing minor observation in your recent comment
NOTE : make issue only for this point : "300ms chip flicker after Clear All"

Also I want before making the new issue please read this comment which you said in issue of this PR where you told one bug related to - "useDebounce to return a [value, setValue] tuple"

is both things said in that issue comment and the one you said in this PR comment are same ?
if then please do a honest reasoning about it and then try to find what best issue to make and must enhance the project codebase and hence efficiency

Make sure new issue must have complete reasoning and detailed description about whats that issue and where it makes the codebase bad and how to work on that new issue

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch the specific comment from issue `#161`
gh api repos/kunalverma2512/CodeLens/issues/161/comments --jq '.[] | select(.id == 4701401810 or (.html_url | contains("4701401810"))) | {id: .id, body: .body, url: .html_url}'

echo ""
echo "=== All comments on issue 161 ==="
gh api repos/kunalverma2512/CodeLens/issues/161/comments --jq '.[] | {id: .id, url: .html_url, snippet: .body[0:300]}'

Length of output: 12626


🏁 Script executed:

#!/bin/bash
gh issue create \
  --repo kunalverma2512/CodeLens \
  --assignee kunalverma2512 \
  --title "UX: Active filter chips flicker/persist ~300ms after clicking \"Clear All\" on Practice Page" \
  --body "## Summary

After clicking either **\"Clear All\"** button on the Practice Page, active filter chips (e.g., the search badge \`Active: \"foo\"\`) remain visible for approximately **300 milliseconds** before disappearing. This creates a visual flicker that makes the UI feel unresponsive and inconsistent — the user clicks the button, the list resets, but the chip badges linger briefly before going away.

This is a pre-existing UX defect, discovered during the review of PR `#198` (which fixed the related crash \`ReferenceError: setDebouncedSearch is not defined\`).

---

## Root Cause

In \`frontend/src/pages/PracticePage.jsx\`, the computed variable \`hasFilters\` — which controls the visibility of the active filter chip section — reads from \`debouncedSearch\` instead of \`searchQuery\`:

\`\`\`js
// Current (problematic)
const hasFilters = debouncedSearch || selectedTags.length > 0 || ratingIdx !== 0 || sortBy !== \"rating-asc\";
\`\`\`

\`debouncedSearch\` is produced by the \`useDebounce\` hook (\`frontend/src/hooks/useDebounce.js\`) with a 300ms delay. It only updates after the timer fires. So when \`clearAll()\` calls \`setSearchQuery(\"\")\`:

1. \`searchQuery\` becomes \`\"\"\" immediately — the input field clears ✅
2. \`debouncedSearch\` stays at the old value for ~300ms ⚠️
3. Because \`hasFilters\` depends on \`debouncedSearch\`, the chip section remains rendered for that 300ms window ⚠️
4. After 300ms, \`debouncedSearch\` catches up, \`hasFilters\` becomes falsy, and the chips vanish

This is **semantically incorrect**: \`hasFilters\` is a UI visibility gate for _what the user has entered_, not a gate for _what query is currently being debounced to the filter logic_. The two should not be conflated.

---

## Why This Matters for the Codebase

- **Inconsistency:** Other filter states (\`selectedTags\`, \`ratingIdx\`, \`sortBy\`) reset and hide their chips instantly because they are not debounced. Only the search chip has this lag, creating an uneven UX.
- **Semantic incorrectness:** Using a debounced value to drive immediate UI visibility is architecturally wrong. \`debouncedSearch\` exists to throttle expensive operations (e.g., API/filter calls), not to gate chip visibility.
- **User confusion:** The user may click \"Clear All\" again, thinking the first click did not register, because the chip is still showing.

---

## Historical Context

During issue `#161`, an alternative approach was discussed: modifying \`useDebounce\` to return a \`[value, setter]\` tuple so the debounced value could be manually reset to \`\"\"\` in \`clearAll()\`. That approach was explicitly deferred to a separate issue because it adds hook API complexity and is unnecessary — the chip flicker can be fixed entirely at the component level without touching the hook.

---

## Acceptance Criteria

- [ ] Clicking \"Clear All\" (the inline chip button) causes the active filter chip section to disappear **immediately**, with no visible delay
- [ ] Clicking \"Clear All Filters\" (the empty-results button) causes the same immediate disappearance
- [ ] Normal debounce behavior during typing in the search box is **unaffected** — the filter/list results still debounce correctly at 300ms
- [ ] No regression in other filter chip states (tags, rating, sort)
- [ ] No console errors

---

## Files to Investigate

- \`frontend/src/pages/PracticePage.jsx\` — specifically the \`hasFilters\` computed variable and where it controls chip visibility
- \`frontend/src/hooks/useDebounce.js\` — for context on what \`debouncedSearch\` represents (read-only derived value, not a UI state)

---

## References

- PR `#198` — Fix: ReferenceError crash on Clear All (where this was first observed)
- Issue `#161` — Original crash report (where the tuple approach was considered and deferred)

/cc `@kunalverma2512`"

Length of output: 4133



@kunalverma2512 — here's the full honest breakdown, followed by the new issue link.


🔍 Are Both Things the Same?

No — they are siblings targeting the same UX symptom, but through different layers.

Issue #161 "Option 2" (tuple approach) PR #198 "chip flicker" observation
Symptom 300ms lag before filter results clear 300ms lag where filter chips stay visible
Fix layer useDebounce hook — change return shape to [value, setter] PracticePage.jsx — use searchQuery instead of debouncedSearch in hasFilters
Complexity High — new hook API surface, potential regressions in future callers Minimal — one-word change, local to one variable
Semantically correct? Debatable — breaks the "read-only derived value" contract of the hook ✅ Yes — hasFilters is about UI state (what user typed), not query state
Verdict Over-engineered for this symptom Correct, precise fix

Key insight: The hasFilters component-level fix completely subsumes the need for the tuple approach. If hasFilters reads from searchQuery (which clears instantly), the chips vanish immediately, and there's no longer any reason to manually reset debouncedSearch. The hook stays clean and unchanged.


✅ New Issue Created

#205UX: Active filter chips flicker/persist ~300ms after clicking "Clear All" on Practice Page

The issue contains:

  • Full root cause explanation with code context
  • Why this is semantically incorrect (two different concerns conflated into one variable)
  • Why the tuple approach from #161 is unnecessary
  • Clear acceptance criteria covering both buttons, debounce behavior, and regression checks
  • Cross-references to PR #198 and issue #161 for historical context

🐇✨

@kunalverma2512

Copy link
Copy Markdown
Owner

@ShreyaSinghal22 Well done
I am mergingn this PR and wanted that you actively work on more issues plus try to come up with creative ideas to enhance and grow both frontend, backend , and every layer this project is made on and also any feature etc..

Come up on our communication channel for future collaboration : https://matrix.to/#/#codelensx:matrix.org

Thanks

@kunalverma2512 kunalverma2512 merged commit a280210 into kunalverma2512:main Jun 15, 2026
2 of 3 checks passed
@ShreyaSinghal22

Copy link
Copy Markdown
Contributor Author

@kunalverma2512 thankyou for assigning this issue to me. I will surely see through and analyse codelens and would love to contribute more in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ReferenceError: setDebouncedSearch is not defined when clicking 'Clear All' on Practice Page

2 participants