polymer icon indicating copy to clipboard operation
polymer copied to clipboard

Bug in observe property handling in dom-repeat (__handleObservedPaths)

Open michalsukupcak opened this issue 8 years ago • 0 comments

Description

Hey,

I think I found a bug in handling of the dom-repeat template's observe property.

If the observe property should observe a path to an item's subproperty, such as this:

[
    {
        mainObject: { 
            subObject: {
                value: null
            }
        }
    }
]

The following doesn't work (leaving out nonessential attributes), even though it should: <template is="dom-repeat" observe="mainObject.subObject.value"> Omiting the first-level subproperty does the trick, but I don't think this is the expected behavior: <template is="dom-repeat" observe="subObject.value">

I believe the issue lies here:

polymer/lib/elements/dom-repeat.html:

    __handleObservedPaths(path) {
      // Handle cases where path changes should cause a re-sort/filter
      if (this.__sortFn || this.__filterFn) {
        if (!path) {
          // Always re-render if the item itself changed
          this.__debounceRender(this.__render, this.delay);
        } else if (this.__observePaths) {
          // Otherwise, re-render if the path changed matches an observed path
          path = path.substring(path.indexOf('.') + 1);
          let paths = this.__observePaths;
          for (let i=0; i<paths.length; i++) {
            if (paths[i].indexOf(path) === 0) {
              this.__debounceRender(this.__render, this.delay);
            }
          }
        }
      }
    }

Specifically here: path = path.substring(path.indexOf('.') + 1); This line removes the first object from the notified item path, changing mainObject.subObject.value from the example above to subObject.value, which is then never found in the for loop, as it compares the shortened path to paths from observe="mainObject.subObject.value" property.

I hope the live demo helps:

Live Demo

http://jsbin.com/haqonocufo/1/edit?html,output

Steps to Reproduce

Create array of complex objects, bind the array to dom-repeat template, create a filter function, set a subproperty to observe path of the subproperty and change the subproperty after initial render.

Expected Results

Template gets re-rendered because of the observed subproperty change.

Actual Results

Template doesn't get re-rendered.

Versions

  • Polymer: v2.3.1
  • webcomponents: v1.0.20

michalsukupcak avatar Dec 11 '17 17:12 michalsukupcak