-
Notifications
You must be signed in to change notification settings - Fork 23
Description
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:
remount/src/strategies/mutation_observer.js
Lines 76 to 79 in 8bd440e
| 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.