Skip to content

Commit c6ed764

Browse files
author
Ryan A. Johnson
committed
fix(onWebComponentsReady): remove wcr handler after first run
1 parent 10e97b6 commit c6ed764

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utils/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ export function onWebComponentsReady (cb = NOOP) {
203203
// polyfill already finished loading, execute callback immediately
204204
_callback();
205205
} else {
206-
// execute callback when polyfill has finished loading
207-
window.addEventListener('WebComponentsReady', function () {
206+
let wcrHandler = function () {
208207
_callback();
209-
});
208+
// remove listener to prevent additional execution of the handler
209+
window.removeEventListener('WebComponentsReady', wcrHandler);
210+
};
211+
// execute callback when polyfill has finished loading
212+
window.addEventListener('WebComponentsReady', wcrHandler);
210213
}
211214
} else {
212215
// No polyfills detected, execute callback immediately

0 commit comments

Comments
 (0)