-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Avoid multiple browser history push when navigating or using search bar. #1351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ export const Inbox = ({ viewType }: InboxProps) => { | |
useEffect(() => { | ||
const newSearchParams = new URLSearchParams(searchParams); | ||
newSearchParams.set('sortBy', selectedSortOrder); | ||
setSearchParams(newSearchParams); | ||
setSearchParams(newSearchParams, { replace: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Most setSearchParams calls already use { replace: true }, but one in SearchBar needs attention Found one instance in
All other instances already properly use
🔗 Analysis chainLGTM! Prevents duplicate history entries for sort order changes. The addition of Let's verify other URL parameter updates in the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for other setSearchParams calls that might need similar treatment
# Search for setSearchParams calls without replace option
rg "setSearchParams\([^)]*\)" --type ts --type tsx -A 2 -B 2
Length of output: 90 Script: #!/bin/bash
# Let's try a different approach using ripgrep without file type filters
# and then filter results in post-processing
# Search for setSearchParams calls
rg "setSearchParams\(" -A 2 -B 2
Length of output: 2372 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TY rabbit! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbacherycz You're welcome! /(=^ x ^=)\ |
||
}, [selectedSortOrder]); | ||
|
||
const shouldShowSearchResults = !isFetchingSearchResults && showingSearchResults; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Fix useEffect dependencies and add missing import
The review comment was correct about the implementation issues. Looking at the file content:
location
is not imported but used in dependency arrayuseSearchParams
from 'react-router-dom'searchParams
in the dependency array since that's what it's actually usingApply this fix:
The current implementation is problematic because:
location
variablesearchParams
) is not in the dependency arraysearchParams
, makinglocation.search
unnecessary🔗 Analysis chain
Fix useEffect implementation issues
There are several issues with the current useEffect implementation:
location.search
is used in dependency array but not imported/definedsearchParams
should be in the dependency array since it's used in the effectApply this fix:
Let's verify if location is properly imported elsewhere:
The previous command failed due to typescript extension issue. Let's try a broader search and also look at the actual file content to understand how location is being used and if there are any imports we might have missed.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 107
Script:
Length of output: 4917