Skip to content
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(insights): only load script if we write window.aa #5559

Merged
merged 5 commits into from
Apr 4, 2023

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Mar 22, 2023

Summary

We were attempting to load search-insights, even if window.aa had potentially already been set up by something different.

Result

Only when window[window.AlgoliaAnalyticsObject] is set by InstantSearch it is safe to load search insights, otherwise it will not be used.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 22, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 769588d:

Sandbox Source
InstantSearch.js Configuration
react-instantsearch-app Configuration
example-react-instantsearch-hooks-default-theme Configuration
example-vue-instantsearch-default-theme Configuration

@Haroenv Haroenv marked this pull request as ready for review March 22, 2023 15:57
@Haroenv Haroenv requested review from a team, sarahdayan and aymeric-giraudet and removed request for a team March 22, 2023 15:57
if (!insightsClient) {
if (!potentialInsightsClient) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

before this change, if window.AlgoliaAnalyticsObject wasn't a string, insightsClient still was noop, and thus not null

Comment on lines +84 to -87
window[pointer].shouldAddScript = true;
}

insightsClient = window[pointer];
insightsClient.shouldAddScript = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should only add the script if we wrote window.aa, as otherwise nothing will happen with the script

@Haroenv Haroenv merged commit 3e16ad9 into feat/automatic-insights Apr 4, 2023
@Haroenv Haroenv deleted the fix/insights-load-script-correctly branch April 4, 2023 15:10
Haroenv added a commit that referenced this pull request Apr 18, 2023
* fix(insights): only load script if we write window.aa

* Update packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts

* Update packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts

* fix lint
Haroenv added a commit that referenced this pull request Apr 24, 2023
* fix(insights): only load script if we write window.aa

* Update packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts

* Update packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts

* fix lint
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.

2 participants