Infinite "Searching by meaning..." loading state on back navigation and sequential searches fix - #1447
Merged
Conversation
Contributor
WalkthroughThe search results page tracks active query generations. Image searches ignore loader updates from superseded searches. The image-result effect also responds to ChangesSearch generation tracking
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Contributor
Author
|
@rohan-pandeyy can you please review this PR. |
rohan-pandeyy
approved these changes
Aug 2, 2026
rohan-pandeyy
added a commit
to rohan-pandeyy/PictoPy
that referenced
this pull request
Aug 2, 2026
Resolves SearchResults.tsx: keeps the stale-loader generation guard from AOSSIE-Org#1447 and re-applies the people-query gate on top of it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addressed Issues:
Fixes #1398 : Infinite "Searching by meaning..." loading state on back navigation and sequential searches on searching multiple times.
Problem Statement:
The application enters an unrecoverable, infinite loading state displaying the "Searching by meaning...".
When we search different things more than 3 or 4 times and go back or search again, at one point it crashes o r gets stuck.
Screenshots/Recordings:
PictoPy Before:
624449139-02e06284-a035-4945-80a3-9f7525ad713e.mov
PictoPy After:
Screen.Recording.2026-08-01.at.9.38.42.AM.mov
Additional Notes:
Number of Files Changed: 1
File Name: frontend/src/pages/searchResults/searchResults.tsx
Problems that are Fixed:
Total Number of bugs present: 2
Bug 1: A stale search re-opens the loader after a newer search already closed it
In auto mode, the query function falls back to semantic search and dispatches a loading message:
Fix: :
Added a generation counter
(searchGenerationRef)that increments synchronously during render whenever query/mode actually changes (not inside a useEffect, since effects run after render and would leave a timing gap). Each search captures its own generation number when it starts (myGeneration). Before dispatching showLoader, it checks whether its generation is still current — if a newer search has started, the numbers won't match and the dispatch is skipped. This is a plain synchronous comparison, so it can't itself race.Bug 2: Repeating an identical search re-fetches silently, and the loader-hiding effect never re-runs:
This one only shows up when a search is repeated exactly (e.g. "human" → "motorcycle" → "human" again). React Query caches by query key, so the third search hits the same cache entry as the first: it instantly returns the cached results, then quietly refetches in the background to revalidate.
The
useEffectresponsible for hiding the loader only re-runs when data,isSuccess, isError, or isLoadingchange. During that background refetch:1.
isLoadingstaysfalsethe whole time — it's onlytruewhen there's no cached data at all.2. If the refetched results are identical to the cached ones (likely, since the underlying library hasn't changed), React Query reuses the same data reference rather than creating a new one.
hideLoader()is never called — even though Bug 1'sshowLoaderdispatch already turned it back on for that background refetch.Fix::
Added
isFetchingto the effect's dependency array. UnlikeisLoading,isFetchingistruefor the full duration of any fetch — including silent background refetches — and reliably flips back to false when it completes, regardless of whether the data reference changed. This guarantees the effect re-runs and hides the loader once the refetch finishes.Improtant:
- I have tested it for multiple searches multiple times, but on your side please do check it, if it is generating a bug or not.
AI Usage Disclosure:
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Check one of the checkboxes below:
I have used the following AI models and tools: Claude Sonnet - 5
Checklist
Summary by CodeRabbit