Skip to content

Commit 47c4e24

Browse files
authored
Merge pull request #641 from HelixDesignSystem/fix-wcr-handler
[0.18.x] fix(onWebComponentsReady): remove wcr handler after first run
2 parents 10e97b6 + c6ed764 commit 47c4e24

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)