ref(settings): replace browserHistory with useNavigate in organizationProjects#110019
Conversation
| DEFAULT_DEBOUNCE_DURATION | ||
| ), | ||
| [location.pathname, location.query] | ||
| [location.pathname, location.query, navigate] |
There was a problem hiding this comment.
Bug: The useMemo for debouncedSearch has unstable dependencies (location.query and navigate), causing it to be recreated on every search, which resets the debounce timer.
Severity: MEDIUM
Suggested Fix
To stabilize the dependencies, remove location.query and navigate from the useMemo dependency array. The navigate function from useNavigate is guaranteed to be stable and does not need to be a dependency. The debounced function's logic does not depend on the current location.query.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/app/views/settings/organizationProjects/index.tsx#L102
Potential issue: The `debouncedSearch` function is created within a `useMemo` hook that
depends on `location.query`. However, `location.query` is regenerated as a new object on
every render because it is the result of `qs.parse()`. When a search triggers a
navigation, the component re-renders, `location.query` gets a new object reference, and
the `useMemo` hook re-creates the `debouncedSearch` function. This resets the debounce
timer, breaking the debouncing logic for any keystrokes following the first search. The
newly added `navigate` dependency is also unstable and contributes to this issue.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| query: {...location.query, query: searchQuery, cursor: undefined}, | ||
| }, | ||
| {replace: true} | ||
| ), |
There was a problem hiding this comment.
Missing preventScrollReset option in navigate call
Low Severity
The browserHistory.replace shim automatically includes preventScrollReset: true (as documented in browserHistory.tsx with an explicit comment: "Note that useNavigate replace does not automatically prevent scroll reset"). Switching to navigate directly with only {replace: true} drops this behavior, which may cause unwanted scroll-to-top when typing in the search bar, since ScrollRestoration is active in the app layout.


No description provided.