polymer icon indicating copy to clipboard operation
polymer copied to clipboard

dom-repeat not renders correctly

Open niuhf0452 opened this issue 10 years ago • 3 comments

Description

In a special condition, dom-repeat is not rendering correctly, such as following code.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
  <link rel="import" href="bower_components/polymer/polymer.html">
</head>

<body>
  <dom-module id="frame-page">
    <template>
      <template id="i" is="dom-if" if="{{show}}">
        <template id="p" is="dom-repeat" items="{{items}}">
          <template is="dom-if" if="{{show}}">abc</template>
        </template>
        <template id="t" is="dom-repeat" items="{{items}}">
          <div>{{item}}</div>
        </template>
        <iframe></iframe>
      </template>
    </template>
  </dom-module>

  <script>
    var arr1 = []
    var arr2 = [2,3]
    window.addEventListener('WebComponentsReady', function() {
      Polymer({
        is: 'frame-page',
        ready: function() {
          this.show = true
          this.items = arr1
          var self = this;
          setTimeout(function() {
            self.items = arr2
          }, 500)
        }
      });
    })
  </script>

  <frame-page></frame-page>
</body>

</html>

Expected Results and Actual

In the template which id is "t", I expect the items 2 and 3 will show. But they are not showing as my expect.

Browsers Affected

My browser's user agent is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/537.36 Safari/537.36.

Versions

  • Polymer: v1.2.4 (I am not pretty sure whether it will also occur in 1.4.0.)
  • webcomponents: v0.7.20

The reason which I think will lead to this bug

When I check the code in polymer-mini.html, I saw something which I think kind of wired. Polymer.Async._atEndOfMicrotask has reentrant. _lastVal counts larger than it should be. When Polymer.Async.cancel is called

var idx = handle - this._lastVal;

due to the wrong value of _lastVal, idx is also wrong. So it cancels the wrong task.

niuhf0452 avatar Mar 26 '16 12:03 niuhf0452

Works for me: http://jsbin.com/nikequm/edit?html,output

kaste avatar Mar 30 '16 22:03 kaste

This is probably already covered by https://github.com/Polymer/polymer/issues/2581. Are you using "use strict"?

davidlwatsonjr avatar Apr 13 '16 16:04 davidlwatsonjr

Closing in favor of https://github.com/Polymer/polymer/issues/2581. Let us know if that's not your root cause.

ebidel avatar Apr 13 '16 16:04 ebidel