Repository navigation
[CP Staging] Revert "fix: stop Search re-firing an identical query on unrelated Onyx updates" #98548
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
[CP Staging] Revert "fix: stop Search re-firing an identical query on unrelated Onyx updates" #98548
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 |
|---|---|---|
|
|
@@ -85,24 +85,26 @@ function useSearchHighlightAndScroll({ | |
| const previousTransactionIDsLocal = Object.keys(previousTransactions ?? {}); | ||
| const transactionsIDs = Object.keys(transactions ?? {}); | ||
|
|
||
| const reportActionsIDs = Object.values(reportActions ?? {}) | ||
| .map((actions) => Object.keys(actions ?? {})) | ||
| .flat(); | ||
| const previousReportActionsIDs = Object.values(previousReportActions ?? {}) | ||
| .map((actions) => Object.keys(actions ?? {})) | ||
| .flat(); | ||
|
|
||
| // Only proceed if we have previous data to compare against | ||
| // This prevents triggering on initial data load | ||
| const hasPreviousReportActions = Object.values(previousReportActions ?? {}).some((actions) => Object.keys(actions ?? {}).length > 0); | ||
| if ((previousTransactionIDsLocal.length === 0 && !hasPreviousReportActions) || searchTriggeredRef.current) { | ||
| if ((previousTransactionIDsLocal.length === 0 && previousReportActionsIDs.length === 0) || searchTriggeredRef.current) { | ||
| return; | ||
| } | ||
|
|
||
| // Only chat searches are driven by report actions, so the rest skip walking that collection entirely. | ||
| const reportActionsIDs = isChat ? Object.values(reportActions ?? {}).flatMap((actions) => Object.keys(actions ?? {})) : []; | ||
| const previousReportActionsIDs = isChat ? Object.values(previousReportActions ?? {}).flatMap((actions) => Object.keys(actions ?? {})) : []; | ||
|
|
||
| const previousTransactionsIDsSet = new Set(previousTransactionIDsLocal); | ||
| const previousReportActionsIDsSet = new Set(previousReportActionsIDs); | ||
| const hasTransactionsIDsChange = transactionsIDs.length !== previousTransactionIDsLocal.length || transactionsIDs.some((id) => !previousTransactionsIDsSet.has(id)); | ||
| const hasReportActionsIDsChange = reportActionsIDs.some((id) => !previousReportActionsIDsSet.has(id)); | ||
|
|
||
| // Check if there is a change in the transactions or report actions list | ||
| if ((isChat ? hasReportActionsIDsChange : hasTransactionsIDsChange) || hasPendingSearchRef.current) { | ||
| if ((!isChat && hasTransactionsIDsChange) || hasReportActionsIDsChange || hasPendingSearchRef.current) { | ||
| // Skip if offline, or if the user has navigated to a different fullscreen page entirely. | ||
| // An RHP layered on top of Search makes `isFocused` false but keeps Search as the topmost | ||
| // fullscreen route, so we still want to refetch — otherwise the snapshot can't reflect | ||
|
|
@@ -114,32 +116,19 @@ function useSearchHighlightAndScroll({ | |
| } | ||
| hasPendingSearchRef.current = false; | ||
|
|
||
| // Transaction Onyx keys are `transactions_<id>` but search results yield bare IDs, so read the ID off the value. | ||
| const addedTransactionIDs: string[] = []; | ||
| const currentTransactionIDs: string[] = []; | ||
| for (const [key, transaction] of Object.entries(transactions ?? {})) { | ||
| const transactionID = transaction?.transactionID; | ||
| if (!transactionID) { | ||
| continue; | ||
| } | ||
| currentTransactionIDs.push(transactionID); | ||
| if (!previousTransactionsIDsSet.has(key)) { | ||
| addedTransactionIDs.push(transactionID); | ||
| } | ||
| } | ||
|
|
||
| const newIDs = isChat ? reportActionsIDs : transactionsIDs; | ||
|
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.
In the non-chat branch Useful? React with 👍 / 👎. |
||
| let currentSearchResultIDs: string[] = []; | ||
| if (searchResultsData) { | ||
| currentSearchResultIDs = isChat ? extractReportActionIDsFromSearchResults(searchResultsData) : extractTransactionIDsFromSearchResults(searchResultsData); | ||
| } | ||
| const existingSearchResultIDsSet = new Set(currentSearchResultIDs); | ||
| const hasAGenuinelyNewID = (isChat ? reportActionsIDs : addedTransactionIDs).some((id) => !existingSearchResultIDsSet.has(id)); | ||
| const hasAGenuinelyNewID = newIDs.some((id) => !existingSearchResultIDsSet.has(id)); | ||
|
|
||
| // Only skip search if there are no new items AND search results aren't empty | ||
| // This ensures deletions that result in empty data still trigger search | ||
| if (!hasAGenuinelyNewID && currentSearchResultIDs.length > 0) { | ||
| const currentIDsSet = new Set(isChat ? reportActionsIDs : currentTransactionIDs); | ||
| const hasDeletedID = currentSearchResultIDs.some((id) => !currentIDsSet.has(id)); | ||
| const newIDsSet = new Set(newIDs); | ||
| const hasDeletedID = currentSearchResultIDs.some((id) => !newIDsSet.has(id)); | ||
| if (!hasDeletedID) { | ||
| return; | ||
| } | ||
|
|
||
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.
For a non-chat search this condition still enters when
hasReportActionsIDsChangeis true. The Search screen subscribes to the global report-actions collection and passes it into this hook (src/components/Search/index.tsx:170,src/components/Search/index.tsx:234-244), so sending or receiving any new chat action while an expense search page is open re-runs the current expense search even though no transaction changed; becausenewIDsbelow is the transaction key list, the later filter cannot recognize the report action as irrelevant. Keep report-action changes inside the chat branch.Useful? React with 👍 / 👎.