Skip to content

build(fix): search bar not clearing on navigation#1541

Merged
johbaxter merged 2 commits intodevfrom
1502-search-bar-not-clearing-on-navigation
Jul 17, 2025
Merged

build(fix): search bar not clearing on navigation#1541
johbaxter merged 2 commits intodevfrom
1502-search-bar-not-clearing-on-navigation

Conversation

@JaganSomannaKanini
Copy link
Copy Markdown
Contributor

Description

Once we search for anything in the global search, after navigation the search is not cleared. With this PR it is fixed.

Changes Made

Using the useLocation from the react router, we will be able to get the current route with this we can clear the search. On every route change the search is cleared.

How to Test

  1. On start, search for an already created app/db/function, etc.
  2. Navigate away and back.
  3. After the search click on the app you want to open, the app opens in a new window. Come back to the window where the search was performed, the search will be cleared.

Notes

  • Searched for a app
image
  • Then navigated to the App/db/function, etc.
image
  • Searched for an App and clicked on the link to open the App.
image

Navigated back to the window where the search was performed, the search is cleared.

image

@JaganSomannaKanini JaganSomannaKanini requested a review from a team as a code owner July 17, 2025 12:02
@JaganSomannaKanini JaganSomannaKanini linked an issue Jul 17, 2025 that may be closed by this pull request
3 tasks
@github-actions
Copy link
Copy Markdown

@CodiumAI-Agent /describe

@QodoAI-Agent
Copy link
Copy Markdown

Title

build(fix): search bar not clearing on navigation


User description

Description

Once we search for anything in the global search, after navigation the search is not cleared. With this PR it is fixed.

Changes Made

Using the useLocation from the react router, we will be able to get the current route with this we can clear the search. On every route change the search is cleared.

How to Test

  1. On start, search for an already created app/db/function, etc.
  2. Navigate away and back.
  3. After the search click on the app you want to open, the app opens in a new window. Come back to the window where the search was performed, the search will be cleared.

Notes

  • Searched for a app
image
  • Then navigated to the App/db/function, etc.
image
  • Searched for an App and clicked on the link to open the App.
image

Navigated back to the window where the search was performed, the search is cleared.

image

PR Type

Bug fix


Description

  • Clear global search on each route change

  • Reset search after selecting an autocomplete option

  • Import and use useLocation from React Router

  • Add useEffect hook to trigger search clearing


Changes diagram

flowchart LR
  A["Route Change"] -->|triggers| B["useEffect hook"]
  B -->|calls| C["configStore.setGlobalSearch('')"]
  D["Option Selection"] -->|onClick| E["setRecentSearch"]
  E -->|then| C
Loading

Changes walkthrough 📝

Relevant files
Bug fix
Search.tsx
Add search clearing on navigation and selection                   

packages/client/src/components/shared/Search.tsx

  • Imported useEffect and useLocation hooks
  • Added useEffect to clear globalSearch on route change
  • Cleared globalSearch state after option selection
  • +10/-3   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /review

    @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /improve

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Unused Variable

    The navigate variable from useNavigate is declared but never used. Consider removing it to clean up the code.

    // TODO: navigation should be done through callback
    const navigate = useNavigate();
    const location = useLocation();
    Effect Dependencies

    The useEffect hook resets the search on route changes but omits configStore in its dependency array. This can lead to stale closures; add configStore or deconstruct its setter to the dependencies.

    useEffect(() => {
     configStore.setGlobalSearch('');
    }, [location?.pathname]);
    Comma Operator

    Inside the onClick handler, the comma operator is used to chain setRecentSearch and setGlobalSearch, which is confusing. Use separate statements or semicolons for clarity.

        }),
        configStore.setGlobalSearch(''); // Clear search after selection
    }}

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix onClick syntax and close menu

    The comma operator inside the onClick handler is confusing and can cause unexpected
    behavior. Use semicolons to separate calls and also close the dropdown after
    selection.

    packages/client/src/components/shared/Search.tsx [361-367]

     onClick={() => {
    -    configStore.setRecentSearch({
    -        label: option.label,
    -        id: option.id,
    -        type: option.section,
    -    }),
    -    configStore.setGlobalSearch(''); // Clear search after selection
    +  configStore.setRecentSearch({
    +    label: option.label,
    +    id: option.id,
    +    type: option.section,
    +  });
    +  configStore.setGlobalSearch('');
    +  setOpen(false);
     }}
    Suggestion importance[1-10]: 8

    __

    Why: Replacing the comma operator with proper semicolons fixes a potential syntax bug in the onClick handler and adding setOpen(false) correctly closes the menu after a selection.

    Medium
    General
    Close dropdown on navigation

    Also close the Autocomplete dropdown when clearing the search on navigation to avoid
    leaving the menu open. Replace the optional chaining in the dependency array with
    the direct location.pathname.

    packages/client/src/components/shared/Search.tsx [218-220]

     useEffect(() => {
    - configStore.setGlobalSearch('');
    -}, [location?.pathname]);
    +  configStore.setGlobalSearch('');
    +  setOpen(false);
    +}, [location.pathname]);
    Suggestion importance[1-10]: 7

    __

    Why: Adding setOpen(false) ensures the Autocomplete menu closes on route change and switching from location?.pathname to location.pathname is correct since location always exists and makes the effect more precise.

    Medium
    Remove optional chaining in effect

    Optional chaining in the effect’s dependency array is unnecessary because location
    always exists. Use the direct location.pathname to ensure the effect runs only when
    the path actually changes.

    packages/client/src/components/shared/Search.tsx [218-220]

     useEffect(() => {
    - configStore.setGlobalSearch('');
    -}, [location?.pathname]);
    +  configStore.setGlobalSearch('');
    +}, [location.pathname]);
    Suggestion importance[1-10]: 4

    __

    Why: Switching from location?.pathname to location.pathname is a minor cleanup because location is always defined, improving readability without affecting functionality.

    Low

    Copy link
    Copy Markdown
    Contributor

    @johbaxter johbaxter left a comment

    Choose a reason for hiding this comment

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

    Looks good to me, ty

    @johbaxter johbaxter merged commit e8aa56f into dev Jul 17, 2025
    3 checks passed
    @johbaxter johbaxter deleted the 1502-search-bar-not-clearing-on-navigation branch July 17, 2025 16:32
    @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /update_changelog

    @QodoAI-Agent
    Copy link
    Copy Markdown

    Changelog updates: 🔄

    2025-07-17 *

    Fixed

    • Reset global search input on navigation between routes.

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    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.

    Search Bar not clearing on Navigation

    3 participants