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

Adding method childrenChanged crashes Firefox/Safari #528

Closed
keithamus opened this issue Jun 11, 2014 · 2 comments
Closed

Adding method childrenChanged crashes Firefox/Safari #528

keithamus opened this issue Jun 11, 2014 · 2 comments

Comments

@keithamus
Copy link

Abstract

Having a simple element with a method named childrenChanged in its prototype, when in Firefox or Safai (curiously not Chrome), calls the childrenChanged method hundreds of times per second, resulting in slow/unresponsive scripts and frozen pages.

Test Case

I've put a simple reduced test case up here: http://jsbin.com/cuvap/2 - to which the contents are:

<script src="//cdnjs.cloudflare.com/ajax/libs/polymer/0.3.0/platform.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/polymer/0.3.0/polymer.js"></script>

<polymer-element name="foo-bar">
  <script>
    Polymer('foo-bar', {
      childrenChanged: function () {
         console.log('childrenChanged');
      }
    });
  </script>
</polymer-element>

<foo-bar></foo-bar>

Loading this page in Chrome seems fine, but loading it in Safari or Firefox and checking the log, one can see childrenChanged seems to be recursively called:

screen shot 2014-06-11 at 10 16 33

@sjmiles
Copy link
Contributor

sjmiles commented Jun 11, 2014

Polymer examines your prototype for methods of the form <name>Changed and automatically creates a binding that calls <name>Changed every time property <name> changes.

The children property is a native accessor, and apparently appears to Polymer to be changing continually. We'll have to investigate exactly why this is true, but it's not going to work properly in any case (native accessors are not generally observable).

If you are purposefully trying to watch for changes to children, you should use a MutationObserver instead. Otherwise, you should use a different name for your method.

We have an outstanding issue to resolve one facet of this problem here: #123.

@sorvell
Copy link
Contributor

sorvell commented Aug 12, 2014

This can be very confusing and our plan is to throw a warning and document this better.

Closed in favor of #123.

@sorvell sorvell closed this as completed Aug 12, 2014
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

3 participants