From ddeb75b8cf077baae9b1983ebf7c9297da8229b8 Mon Sep 17 00:00:00 2001 From: Ranjit Patra Date: Wed, 12 Dec 2018 00:26:05 +0530 Subject: [PATCH] Is not working if DOMContentLoaded already fired If `DOMContentLoaded` event already fired and after adding a listener for `DOMContentLoaded` event, then it will not execute. So added a check to resolve() the promise if DOMContentLoaded event already fired. --- modules/common/src/state-transfer-initializer/module.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/common/src/state-transfer-initializer/module.ts b/modules/common/src/state-transfer-initializer/module.ts index 1d6262204..3402725a0 100644 --- a/modules/common/src/state-transfer-initializer/module.ts +++ b/modules/common/src/state-transfer-initializer/module.ts @@ -15,7 +15,11 @@ export function domContentLoadedFactory(doc: Document) { doc.removeEventListener('DOMContentLoaded', contentLoaded); resolve(); }; - doc.addEventListener('DOMContentLoaded', contentLoaded); + if (doc.readyState === 'complete' || doc.readyState === 'loaded') { + resolve(); + } else { + doc.addEventListener('DOMContentLoaded', contentLoaded); + } }); }