From 51a2292fbdaced0eba1df1b6e6ea9aaf7621815d Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Thu, 13 Apr 2023 18:30:46 -0400 Subject: [PATCH] Fix display ad event race condition (#19326) * Mitigate race condition for async loaded billboard * Put observeDisplayAds in billboard.js --- app/javascript/packs/billboard.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/javascript/packs/billboard.js b/app/javascript/packs/billboard.js index 6187e5a92..0b88b84a4 100644 --- a/app/javascript/packs/billboard.js +++ b/app/javascript/packs/billboard.js @@ -23,6 +23,11 @@ async function generateDisplayAd(element) { element.innerHTML = ''; element.appendChild(generatedElement); setupDisplayAdDropdown(); + // This is called here because the ad is loaded asynchronously. + // The original code is still in the asset pipeline, so is not importable. + // This could be refactored to be importable as we continue that migration. + // eslint-disable-next-line no-undef + observeDisplayAds(); } }