From 4fb639861f76dff8ca3da3be11afba56c6f72779 Mon Sep 17 00:00:00 2001 From: cea2aj <42848445+cea2aj@users.noreply.github.com> Date: Mon, 24 May 2021 16:00:59 -0400 Subject: [PATCH 1/3] 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. --- layouts/html.hbs | 1 + script/partials/sdk-js-script-tags.hbs | 2 -- .../VerticalFullPageMapOrchestrator.js | 2 +- .../vertical-full-page-map/page-setup.js | 30 ++++--------------- .../vertical-full-page-map/page.html.hbs | 3 +- ..._full_page_map_with_filters.html.hbs.patch | 4 +-- tests/script/partials/sdk-js-script-tags.js | 4 --- 7 files changed, 10 insertions(+), 36 deletions(-) diff --git a/layouts/html.hbs b/layouts/html.hbs index d41854428..2563ebd2c 100644 --- a/layouts/html.hbs +++ b/layouts/html.hbs @@ -80,6 +80,7 @@ diff --git a/script/partials/sdk-js-script-tags.hbs b/script/partials/sdk-js-script-tags.hbs index 4f93801be..3f916e6cd 100644 --- a/script/partials/sdk-js-script-tags.hbs +++ b/script/partials/sdk-js-script-tags.hbs @@ -6,11 +6,9 @@ \ No newline at end of file diff --git a/static/js/theme-map/VerticalFullPageMapOrchestrator.js b/static/js/theme-map/VerticalFullPageMapOrchestrator.js index b5099e95a..e75bc1926 100644 --- a/static/js/theme-map/VerticalFullPageMapOrchestrator.js +++ b/static/js/theme-map/VerticalFullPageMapOrchestrator.js @@ -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 diff --git a/templates/vertical-full-page-map/page-setup.js b/templates/vertical-full-page-map/page-setup.js index 9e01130d2..48540c3b8 100644 --- a/templates/vertical-full-page-map/page-setup.js +++ b/templates/vertical-full-page-map/page-setup.js @@ -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(); } \ No newline at end of file diff --git a/templates/vertical-full-page-map/page.html.hbs b/templates/vertical-full-page-map/page.html.hbs index 7302b1077..ea861d123 100644 --- a/templates/vertical-full-page-map/page.html.hbs +++ b/templates/vertical-full-page-map/page.html.hbs @@ -17,8 +17,7 @@ {{> templates/vertical-full-page-map/script/locationbias modifier="main" }} {{> templates/vertical-full-page-map/script/locationbias modifier="mobileMap" }} {{/script/core }} - +
diff --git a/test-site/pages-patches/locations_full_page_map_with_filters.html.hbs.patch b/test-site/pages-patches/locations_full_page_map_with_filters.html.hbs.patch index f4cc27221..fca029815 100644 --- a/test-site/pages-patches/locations_full_page_map_with_filters.html.hbs.patch +++ b/test-site/pages-patches/locations_full_page_map_with_filters.html.hbs.patch @@ -1,5 +1,5 @@ ---- locations_full_page_map_with_filters.html.hbs -+++ locations_full_page_map_with_filters.html.hbs +--- templates/vertical-full-page-map/page.html.hbs 2021-05-24 14:53:55.000000000 -0400 ++++ test-site/pages/locations_full_page_map_with_filters.html.hbs 2021-05-24 14:58:17.000000000 -0400 @@ -1,7 +1,7 @@ {{#> layouts/html pageWrapperCss="YxtPage-wrapper--mobileListView" }} {{#> script/core }} diff --git a/tests/script/partials/sdk-js-script-tags.js b/tests/script/partials/sdk-js-script-tags.js index f12e37ef0..3492097fa 100644 --- a/tests/script/partials/sdk-js-script-tags.js +++ b/tests/script/partials/sdk-js-script-tags.js @@ -3,24 +3,20 @@ const hbs = require('../../test-utils/hbs'); const defaultOutput = ` `; const jaOutput = ` `; From f8ec0c945d5acb8ed760a8e2814b1b9243cbda93 Mon Sep 17 00:00:00 2001 From: cea2aj <42848445+cea2aj@users.noreply.github.com> Date: Mon, 7 Jun 2021 13:23:38 -0400 Subject: [PATCH 2/3] Clear the builtin location filter after 'search this area' searches (#819) Clear the builtin location filter after 'search this area' searches so that the filter isn't applied on subsequent requests This behavior caused an issue in a techops because builtin location filters override NLP location filters from queries. This would sometimes lead to no results or incorrect results if a user searched for a specific location after dragging the map or clicking the 'search this area' button. J=TECHOPS-650 TEST=manual View the network tab and confirm that the builtin filter is only applied during 'search this area' searches. Test that using the search bar to find results near a specific location works. Product also tested this change. --- static/js/theme-map/VerticalFullPageMapOrchestrator.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/js/theme-map/VerticalFullPageMapOrchestrator.js b/static/js/theme-map/VerticalFullPageMapOrchestrator.js index e75bc1926..7aa7334e4 100644 --- a/static/js/theme-map/VerticalFullPageMapOrchestrator.js +++ b/static/js/theme-map/VerticalFullPageMapOrchestrator.js @@ -597,6 +597,7 @@ class VerticalFullPageMapOrchestrator extends ANSWERS.Component { useFacets: true }); this.updateMostRecentSearchState(); + this.core.clearStaticFilterNode('SearchThisArea'); } /** From fb6914038aab7cbd9fd56a0b47b02c6c85fb0bde Mon Sep 17 00:00:00 2001 From: cea2aj <42848445+cea2aj@users.noreply.github.com> Date: Mon, 7 Jun 2021 15:20:25 -0400 Subject: [PATCH 3/3] Bump version numbers to 1.21.1 (#821) Bump version numbers to 1.21.1 J=none TEST=non --- package-lock.json | 2 +- package.json | 2 +- static/package-lock.json | 2 +- static/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index aa6f50f58..cde675738 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "answers-hitchhiker-theme", - "version": "1.21.0", + "version": "1.21.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9c4c98492..87a4b46ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "answers-hitchhiker-theme", - "version": "1.21.0", + "version": "1.21.1", "description": "A starter answers theme for hitchhikers", "scripts": { "test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --verbose", diff --git a/static/package-lock.json b/static/package-lock.json index dbc2bb216..775425cd2 100644 --- a/static/package-lock.json +++ b/static/package-lock.json @@ -1,6 +1,6 @@ { "name": "answers-hitchhiker-theme", - "version": "1.21.0", + "version": "1.21.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/static/package.json b/static/package.json index 5cc473c98..8581a8d37 100644 --- a/static/package.json +++ b/static/package.json @@ -1,6 +1,6 @@ { "name": "answers-hitchhiker-theme", - "version": "1.21.0", + "version": "1.21.1", "description": "Toolchain for use with the HH Theme", "main": "Gruntfile.js", "scripts": {