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 locator bundle race condition #786

Merged
merged 13 commits into from
May 24, 2021
1 change: 1 addition & 0 deletions layouts/html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<script>
document.addEventListener('DOMContentLoaded', function () {
{{> script/on-document-load}}
initAnswers();
});
</script>
<script src="{{relativePath}}/bundle.js" data-webpack-inline></script>
Expand Down
2 changes: 0 additions & 2 deletions script/partials/sdk-js-script-tags.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
<script
src="{{> script/partials/sdk-url sdkAsset="answers-modern.min.js" locale=locale sdkVersion=sdkVersion}}"
type="module"
onload="initAnswers()"
></script>
<script
src="{{> script/partials/sdk-url sdkAsset="answers.min.js" locale=locale sdkVersion=sdkVersion}}"
nomodule
onload="initAnswers()"
defer
></script>
2 changes: 1 addition & 1 deletion static/js/theme-map/VerticalFullPageMapOrchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class VerticalFullPageMapOrchestrator extends ANSWERS.Component {
* The default zoom level for the map
* @type {number}
*/
this.defaultZoom = this.providerOptions.zoom || 14;
this.defaultZoom = this.providerOptions.zoom || 4;

/**
* The current zoom level of the map
Expand Down
29 changes: 3 additions & 26 deletions templates/vertical-full-page-map/page-setup.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
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();
}
}

/**
* 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();
}
5 changes: 3 additions & 2 deletions templates/vertical-full-page-map/page.html.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{#> layouts/html pageWrapperCss="YxtPage-wrapper--mobileListView" }}
{{#> script/core }}
{{> cards/all }}
{{> theme-components/theme-map/script}}
cea2aj marked this conversation as resolved.
Show resolved Hide resolved
{{> theme-components/vertical-full-page-map/script}}
{{!-- {{> templates/vertical-full-page-map/collapsible-filters/page-setup }} --}}
{{> templates/vertical-full-page-map/page-setup }}
{{> templates/vertical-full-page-map/script/searchbar }}
Expand All @@ -17,8 +19,7 @@
{{> templates/vertical-full-page-map/script/locationbias modifier="main" }}
{{> templates/vertical-full-page-map/script/locationbias modifier="mobileMap" }}
{{/script/core }}
<script id="js-answersLocatorBundleScript" src="{{relativePath}}/locator-bundle.js"
onload="window.locatorBundleLoaded = true;" defer></script>
<script id="js-answersLocatorBundleScript" src="{{relativePath}}/locator-bundle.js" defer></script>
<div class="Answers AnswersVerticalMap CollapsibleFilters VerticalFullPageMap VerticalFullPageMap--mobileListView js-answersVerticalFullPageMap">
<div class="Answers-content">
<div class="Answers-contentWrap js-locator-contentWrap" role="region" aria-label="{{ translate phrase="Main location search" }}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
--- locations_full_page_map_with_filters.html.hbs
+++ locations_full_page_map_with_filters.html.hbs
@@ -1,7 +1,7 @@
{{#> layouts/html pageWrapperCss="YxtPage-wrapper--mobileListView" }}
{{#> script/core }}
--- templates/vertical-full-page-map/page.html.hbs 2021-05-24 11:38:14.000000000 -0400
+++ test-site/pages/locations_full_page_map_with_filters.html.hbs 2021-05-24 11:41:13.000000000 -0400
@@ -3,7 +3,7 @@
{{> cards/all }}
{{> theme-components/theme-map/script}}
{{> theme-components/vertical-full-page-map/script}}
- {{!-- {{> templates/vertical-full-page-map/collapsible-filters/page-setup }} --}}
+ {{> templates/vertical-full-page-map/collapsible-filters/page-setup }}
{{> templates/vertical-full-page-map/page-setup }}
{{> templates/vertical-full-page-map/script/searchbar }}
{{> templates/vertical-full-page-map/script/spellcheck }}
@@ -9,7 +9,7 @@
@@ -11,7 +11,7 @@
{{> templates/vertical-full-page-map/script/verticalresultscount }}
{{> templates/vertical-full-page-map/script/appliedfilters }}
{{!-- {{> templates/vertical-full-page-map/script/sortoptions }} --}}
Expand All @@ -18,7 +18,7 @@
{{!-- {{> templates/vertical-full-page-map/script/filterbox }} --}}
{{> templates/vertical-full-page-map/script/verticalresults }}
{{> templates/vertical-full-page-map/script/pagination }}
@@ -32,19 +32,19 @@
@@ -34,19 +34,19 @@
<div class="Answers-resultsHeaderTop">
{{> templates/vertical-full-page-map/markup/verticalresultscount }}
{{> templates/vertical-full-page-map/markup/appliedfilters }}
Expand Down
4 changes: 0 additions & 4 deletions tests/script/partials/sdk-js-script-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ const hbs = require('../../test-utils/hbs');
const defaultOutput = `<script
src="https://assets.sitescdn.net/answers/v1.8/answers-modern.min.js"
type="module"
onload="initAnswers()"
></script>
<script
src="https://assets.sitescdn.net/answers/v1.8/answers.min.js"
nomodule
onload="initAnswers()"
defer
></script>`;

const jaOutput = `<script
src="https://assets.sitescdn.net/answers/v1.8/ja-answers-modern.min.js"
type="module"
onload="initAnswers()"
></script>
<script
src="https://assets.sitescdn.net/answers/v1.8/ja-answers.min.js"
nomodule
onload="initAnswers()"
defer
></script>`;

Expand Down