-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix locator bundle race condition (#786)
Fix the race condition which occurs when the search query loads before the locator bundle This fix ensures that the locator bundle executes after Answers loads, but before Answers initializes. The race condition issue was first found on Theme 1.20.1, and it caused the cards to break when the page loaded. I put a fix up in #739, which stopped the page from breaking, but it did not fix the underlying cause of the race condition. This PR fixes the root problem by making the execution order of the javascript consistent. The race condition lead to an issue where two queries were ran on page load. This became a problem in a techops (Zendesk 405748) because the page would load and return no results while being zoomed into Kansas. This PR prevents the double queries from being sent if the locator bundle takes a while to load. There still may be some situations where two queries are sent on page load, but those issues are out of scope of this particular issue. I also zoomed out the map by default so that if no default initial search is supplied, the map will show the entire US rather than be zoomed into Kansas. J=SLAP-1329 TEST=manual Test both Google Maps and Mapbox. Use fiddler to artificially delay the locator bundle. Test iframe and non-iframe experiences.
- Loading branch information
Showing
7 changed files
with
10 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,11 @@ | ||
function addFullPageMap() { | ||
{{> theme-components/theme-map/script}} | ||
{{> theme-components/vertical-full-page-map/script}} | ||
} | ||
|
||
if (window.locatorBundleLoaded) { | ||
addFullPageMap(); | ||
} else { | ||
const locatorBundleScript = document.querySelector('script#js-answersLocatorBundleScript'); | ||
locatorBundleScript.onload = () => { | ||
window.locatorBundleLoaded = true; | ||
locatorBundleScript.dispatchEvent(new Event('vertical-full-page-map-bundle-loaded')); | ||
addFullPageMap(); | ||
} | ||
} | ||
{{> theme-components/theme-map/script}} | ||
{{> theme-components/vertical-full-page-map/script}} | ||
|
||
/** | ||
* Registers listeners on the card once the locator bundle is loaded | ||
* Registers listeners on the card | ||
* | ||
* @param {ANSWERS.Component} card A location card | ||
*/ | ||
function registerVerticalFullPageMapCardListeners(card) { | ||
if (window.locatorBundleLoaded) { | ||
new VerticalFullPageMap.CardListenerAssigner({card: card}).addListenersToCard(); | ||
return; | ||
} | ||
const verticalFullPageMapScript = document.querySelector('script#js-verticalFullPageMapScript'); | ||
verticalFullPageMapScript.addEventListener('vertical-full-page-map-bundle-loaded', () => { | ||
new VerticalFullPageMap.CardListenerAssigner({card: card}).addListenersToCard(); | ||
}); | ||
function registerVerticalFullPageMapCardListeners(card) { | ||
new VerticalFullPageMap.CardListenerAssigner({card: card}).addListenersToCard(); | ||
} |
This file contains 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
4 changes: 2 additions & 2 deletions
4
test-site/pages-patches/locations_full_page_map_with_filters.html.hbs.patch
This file contains 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
This file contains 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