mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 03:11:30 +03:00
Start elm render mutation observer sooner to make sure pre-rendering doesn't stall.
This commit is contained in:
parent
08aa55a479
commit
c09410a74c
16
index.js
16
index.js
@ -2,6 +2,8 @@ const elmPagesVersion = require("./package.json").version;
|
||||
|
||||
let prefetchedPages;
|
||||
let initialLocationHash;
|
||||
let elmViewRendered = false;
|
||||
let headTagsAdded = false;
|
||||
|
||||
module.exports = function pagesInit(
|
||||
/** @type { mainElmModule: { init: any } } */ { mainElmModule }
|
||||
@ -11,6 +13,13 @@ module.exports = function pagesInit(
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
document.addEventListener("DOMContentLoaded", _ => {
|
||||
new MutationObserver(function() {
|
||||
elmViewRendered = true;
|
||||
if (headTagsAdded) {
|
||||
document.dispatchEvent(new Event("prerender-trigger"));
|
||||
}
|
||||
}).observe(document.body, { attributes: true, childList: true, subtree: true});
|
||||
|
||||
loadContentAndInitializeApp(mainElmModule).then(resolve, reject);
|
||||
});
|
||||
})
|
||||
@ -45,11 +54,10 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
|
||||
fromElm.head.forEach(headTag => {
|
||||
appendTag(headTag);
|
||||
});
|
||||
|
||||
new MutationObserver(function() {
|
||||
headTagsAdded = true;
|
||||
if (elmViewRendered) {
|
||||
document.dispatchEvent(new Event("prerender-trigger"));
|
||||
}).observe(document.body, { attributes: true, childList: true, subtree: true});
|
||||
|
||||
}
|
||||
} else {
|
||||
setupLinkPrefetching();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user