Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MutationObserver strategy fails when script included in <head> #34

Open
edsrzf opened this issue Jun 22, 2020 · 1 comment
Open

MutationObserver strategy fails when script included in <head> #34

edsrzf opened this issue Jun 22, 2020 · 1 comment

Comments

@edsrzf
Copy link

edsrzf commented Jun 22, 2020

The MutationObserver strategy fails when the script defining elements is included inside the <head> tag, without using defer or async on the script tag. The error is:

Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.

The site of the error is here:

observer.observe(document.body, {
childList: true,
subtree: true
})

The cause is that, inside <head> where the script is being evaluated, document.body does not yet exist.

Here is a repl.it link demonstrating the issue: https://repl.it/@EvanShaw2/Remount-MutationObserver-strategy-issue (This code forces all browsers to use the MutationObserver strategy, even if they support custom elements.)

It would be possible to get around this by calling Remount.define inside a jQuery $().ready event handler or equivalent native JS, which would ensure that document.body exists.

It would be nice if this limitation were documented. Even better if it were handled by remount itself.

@rstacruz
Copy link
Owner

rstacruz commented Apr 9, 2022

Interesting - maybe it can also observe document.body || document.documentElement instead 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants