Skip to content

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

@edsrzf

Description

@edsrzf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions