Skip to content

Commit 3636ae6

Browse files
committed
Add await to unblockClickToLoadContent call in runLogin.
Fix return type. Move `displayClickToLoadPlaceholders` subscribe up to avoid race conditions.
1 parent 00e7ee5 commit 3636ae6

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/features/click-to-load.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ class DuckWidget {
471471
if (onError) {
472472
fbElement.addEventListener('error', onError, { once: true })
473473
}
474-
}, { once: true })
474+
})
475475
}
476476
}
477477
// If this is a login button, show modal if needed
@@ -858,7 +858,7 @@ async function replaceClickToLoadElements (targetElement) {
858858
* the page.
859859
* @param {unblockClickToLoadContentRequest} message
860860
* @see {@link ddg-ctp-unblockClickToLoadContent-complete} for the response handler.
861-
* @return {Promise<any>}
861+
* @returns {Promise<void>}
862862
*/
863863
function unblockClickToLoadContent (message) {
864864
return ctl.messaging.request('unblockClickToLoadContent', message)
@@ -870,9 +870,9 @@ function unblockClickToLoadContent (message) {
870870
* shown.
871871
* @param {string} entity
872872
*/
873-
function runLogin (entity) {
873+
async function runLogin (entity) {
874874
const action = entity === 'Youtube' ? 'block-ctl-yt' : 'block-ctl-fb'
875-
unblockClickToLoadContent({ entity, action, isLogin: true })
875+
await unblockClickToLoadContent({ entity, action, isLogin: true })
876876
// Communicate with surrogate to run login
877877
originalWindowDispatchEvent(
878878
createCustomEvent('ddg-ctp-run-login', {
@@ -1782,13 +1782,6 @@ export default class ClickToLoad extends ContentFeature {
17821782
}
17831783
}
17841784
})
1785-
1786-
// Request the current state of Click to Load from the platform.
1787-
// Note: When the response is received, the response handler resolves
1788-
// the readyToDisplayPlaceholders Promise.
1789-
const clickToLoadState = await this.messaging.request('getClickToLoadState')
1790-
this.onClickToLoadState(clickToLoadState)
1791-
17921785
// Listen to message from Platform letting CTL know that we're ready to
17931786
// replace elements in the page
17941787
// eslint-disable-next-line promise/prefer-await-to-then
@@ -1797,10 +1790,14 @@ export default class ClickToLoad extends ContentFeature {
17971790
// TODO: Pass `message.options.ruleAction` through, that way only
17981791
// content corresponding to the entity for that ruleAction need to
17991792
// be replaced with a placeholder.
1800-
(_) => replaceClickToLoadElements()
1793+
() => replaceClickToLoadElements()
18011794
)
18021795

1803-
await readyToDisplayPlaceholders
1796+
// Request the current state of Click to Load from the platform.
1797+
// Note: When the response is received, the response handler resolves
1798+
// the readyToDisplayPlaceholders Promise.
1799+
const clickToLoadState = await this.messaging.request('getClickToLoadState')
1800+
this.onClickToLoadState(clickToLoadState)
18041801

18051802
// Then wait for the page to finish loading, and resolve the
18061803
// afterPageLoad Promise.

0 commit comments

Comments
 (0)