mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 13:16:08 +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 prefetchedPages;
|
||||||
let initialLocationHash;
|
let initialLocationHash;
|
||||||
|
let elmViewRendered = false;
|
||||||
|
let headTagsAdded = false;
|
||||||
|
|
||||||
module.exports = function pagesInit(
|
module.exports = function pagesInit(
|
||||||
/** @type { mainElmModule: { init: any } } */ { mainElmModule }
|
/** @type { mainElmModule: { init: any } } */ { mainElmModule }
|
||||||
@ -11,6 +13,13 @@ module.exports = function pagesInit(
|
|||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
document.addEventListener("DOMContentLoaded", _ => {
|
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);
|
loadContentAndInitializeApp(mainElmModule).then(resolve, reject);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@ -45,11 +54,10 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
|
|||||||
fromElm.head.forEach(headTag => {
|
fromElm.head.forEach(headTag => {
|
||||||
appendTag(headTag);
|
appendTag(headTag);
|
||||||
});
|
});
|
||||||
|
headTagsAdded = true;
|
||||||
new MutationObserver(function() {
|
if (elmViewRendered) {
|
||||||
document.dispatchEvent(new Event("prerender-trigger"));
|
document.dispatchEvent(new Event("prerender-trigger"));
|
||||||
}).observe(document.body, { attributes: true, childList: true, subtree: true});
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setupLinkPrefetching();
|
setupLinkPrefetching();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user