Skip to content

child-observation is broken when Zone.js is present on page and wraps MutationObserver #664

@genadis

Description

@genadis

I'm submitting a bug report

  • Library Version:
    master

  • Browser:
    all

Current behavior:

As can be seen here:
https://github.com/aurelia/templating/blob/master/src/child-observation.js#L160

MutationObserver returned by DOM.createMutationObserver(onChildChange); is being patched, by adding observer.binders = [];

Later it is expected here:
https://github.com/aurelia/templating/blob/master/src/child-observation.js#L67
That the callback's observer contains the binders array.

This is not always the case, and error of the type "Uncaught TypeError: Cannot read property 'length' of undefined" are thrown.

In my use case, aurelia is used as an application inside an Angular application which uses Zone.js. Zone.js wraps the original MutationObserver. So when new MutationObserver() is called a wrapped instance by Zone.js is returned. To this instance .binders is added by aurelia. But in onChildChange() the observer is a different constructor (the browsers original) which does not contain the binders causing the errors.

Expected/desired behavior:

All should work event if window.MutationObserver is not the native browsers constructor.
child observation should not rely on monkey patching window.MutationObserver.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions