Skip to content

Conversation

@mkouzel-yext
Copy link
Contributor

The effect hook that triggers a GDA call has two dependencies: the search results and the search ID. These both change when a search is made. In React 18, these updates are batched together so only one call to GDA gets made when the search is updated. However, in React 17, no batching is performed and updates are handled in order, meaning a call to GDA is made when the search results are updated and when the search ID is updated, even if the same search triggers both updates. This change tracks the search results and only executes a new GDA call if the search results have changed.

J=WAT-4861
TEST=manual

Created a local test site that runs on React 17. Made a local tarball with my changes to search-ui-react using npm pack and pointed the local test site's import of search-ui-react to the tarball. Confirmed that only one GDA call is made per-seasrch.

Also spun up the search-ui-react test-site (which runs on React 18) and confirmed that GDA calls are still made once per search as expected.

The effect hook that triggers a GDA call has two dependencies: the search results and the search ID. These both change when a search is made. In React 18, these updates are batched together so only one call to GDA gets made when the search is updated. However, in React 17, no batching is performed and updates are handled in order, meaning a call to GDA is made when the search results are updated and when the search ID is updated, even if the same search triggers both updates. This change tracks the search results and only executes a new GDA call if the search results have changed.

J=WAT-4861
TEST=manual

Created a local test site that runs on React 17. Made a local tarball with my changes to search-ui-react using npm pack and pointed the local test site's import of search-ui-react to the tarball. Confirmed that only one GDA call is made per-seasrch.

Also spun up the search-ui-react test-site (which runs on React 18) and confirmed that GDA calls are still made once per search as expected.
@mkouzel-yext mkouzel-yext requested a review from a team as a code owner August 4, 2025 18:53
@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2025

Current unit coverage is 91.48841354723707%
Current visual coverage is 78.44611528822055%
Current combined coverage is 92.11229946524064%

Copy link
Contributor

@k-gerner k-gerner left a comment

Choose a reason for hiding this comment

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

I wonder if we could use src/hooks/useDebouncedFunction.ts instead?

Also, do we want to update the package version in this change or does an automated GH workflow action do that?

@mkouzel-yext mkouzel-yext changed the title Debounce generative direct answer calls Deduplicate generative direct answer calls Aug 5, 2025
@mkouzel-yext
Copy link
Contributor Author

I wonder if we could use src/hooks/useDebouncedFunction.ts instead?

We could, as the delta between the searchResults object getting updated and the searchId object getting updated is likely minimal. However, explicitly processing just one of the updates strikes me as better practice. I think that my usage of "debounce" here is incorrect and misleading - I meant "deduplicate".

We absolutely want to bump the patch version, good call. Updating.

@coveralls
Copy link

coveralls commented Aug 5, 2025

Coverage Status

coverage: 88.287% (+0.7%) from 87.593%
when pulling 7bff950 on hotfix/v1.9.4
into 7c5e040 on main.

@mkouzel-yext mkouzel-yext requested a review from Copilot August 5, 2025 15:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where generative direct answer (GDA) calls were duplicated in React 17 due to unbatched state updates, while maintaining single GDA calls in React 18. The fix tracks the previous search results to prevent unnecessary duplicate calls when both search results and search ID change for the same search operation.

  • Introduced state tracking to compare current search results with previously executed search results
  • Updated the effect hook dependency array and logic to prevent duplicate GDA calls
  • Bumped package version from 1.9.3 to 1.9.4

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/components/GenerativeDirectAnswer.tsx Added state tracking to prevent duplicate GDA calls by comparing search results
package.json Version bump to 1.9.4

@mkouzel-yext mkouzel-yext merged commit f4c07d7 into main Aug 7, 2025
25 of 27 checks passed
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.

4 participants