Closed Qard closed 6 years ago
When would one need to use this before the document has loaded?
My use is with rollup. To get the tree-shaking goodness of rollup, modules need to be loaded using import
statements, which happen at the top level and thus end up loading on-load
before the document is ready.
I got this error too, and then i change on-load module:
if(document.body){
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeOldValue: true,
attributeFilter: [KEY_ATTR]
})
}
the error is gone but does it affect the module functionality??
btw, this error happened because using webpack and import statement. I think webpack is trying to run the module before the DOM loaded.
You could perhaps rely on https://github.com/bendrucker/document-ready ? Not sure what webpack does, but that way you can at least be sure certain things don't happen on the DOM before others (:
On Tue, Jan 10, 2017 at 3:18 PM Rahmat Albariqi notifications@github.com wrote:
I got this error too, and then i change on-load module:
if(document.body){ observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeOldValue: true, attributeFilter: [KEY_ATTR] }) }
the error is gone but does it affect the module functionality??
btw, this error happened because using webpack and import statement. I think webpack is trying to run the module before the DOM loaded.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/shama/on-load/issues/14#issuecomment-271586358, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWlet2u2Avp3XQNskQAuy4-k8X2414Qks5rQ5MlgaJpZM4J_w9R .
@yoshuawuyts thanks a lot dude!
I'm using on-load through choo and am getting "Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'."
It would seem
document.body
does not existing yet whenobserver.observe(...)
tries to run. If I wrap the observe call in awindow.onload = () { ... }
it works fine.