Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

MutationObserver Error #840

Closed
MurhafSousli opened this issue Nov 7, 2017 · 3 comments
Closed

MutationObserver Error #840

MurhafSousli opened this issue Nov 7, 2017 · 3 comments

Comments

@MurhafSousli
Copy link

MurhafSousli commented Nov 7, 2017

  • I'm submitting a ...
- [x] bug report
  • Do you want to request a feature or report a bug?

I think it is a bug

  • What is the current behavior?

ERROR ReferenceError: MutationObserver is not defined

  • **If the current behavior is a bug, please provide the steps to reproduce
this.observer = new MutationObserver((mutations: MutationRecord[]) => {
   mutations.forEach(() => {
      // ....
   });
});
const config: MutationObserverInit = {
  // ...
};
this.observer.observe(this.el.nativeElement, config);
  • What is the expected behavior?

No errors

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:

  • Angular version: 5.X
  • Browser: all
  • Language: all
  • OS: all
  • Platform: NodeJs

I tried MutationObserver polyfill, but that one throws another error because it uses window so it won't help in Universal.

I also found this old issue here fgnass/domino#80

Is there a workaround or anything I can do to fix it?

@robisim74
Copy link

MutationObserver is an event on the objects of the DOM, so it is doesn't exist during SSR. Only way I found is detecting before using it:

        if (typeof MutationObserver !== "undefined") {
           this.observer = new MutationObserver((mutations: MutationRecord[]) => {
           ...
           });
        }

@CaerusKaru
Copy link
Member

@robisim74's solution is correct. Domino (the SSR DOM) has no implementation of MutationObserver, although there is an ancient issue open for it in the Domino repo. But this is definitely not a Universal issue, so closing.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants