Skip to content

Loading…

Exception in notifyPath after Polymer/2007-kschaaf-key-disambiguate #2556

Closed
david-saslawsky opened this Issue · 2 comments

2 participants

@david-saslawsky

It seems that there is annotation scoping issue in templates that is now revealed by the changes in 2007-kschaaf-key-disambiguate.

Sorry for the large example, I couldn't make it smaller.

    <dom-module id="x-row">
        <template>
            <p>key=<span>{{model.key}}</span></p>
        </template>
    </dom-module>
    <script>
        Polymer({
            is : 'x-row',

            properties: {
                model: {
                    type: Object
                }
            }
        });
    </script>

    <dom-module id="x-list">
        <template>
            <template is="dom-repeat" items="[[model]]" as="groupData">
                <p>-----</p>
                <template is="dom-repeat" items="[[groupData]]" as="model">
                    <x-row model="[[model]]"></x-row>
                </template>
            </template>
        </template>
    </dom-module>
    <script>
        Polymer({
            is : 'x-list',

            properties: {
                model: {
                    type: Array,
                    value: [
                        [
                            { key:'aaaa' },
                            { key:'bbbb' },
                            { key:'cccc' }
                        ],
                        [
                            { key:'dddd' },
                        ]
                    ]
                }
            }
        });
    </script>

    <x-list id="test"></x-list>
    <input type="button" value="test" onclick="test();">
    <script>
        function test() {
            var test = document.getElementById('test');
            test.set('model.0.1.key', 'dddd');
        }
    </script>

If you click on the test button, there is an exception in the following function from notify-path.html

      _modelForPath: function(path) {
        var dot = path.indexOf('.');    // <--- path is undefined
        return (dot < 0) ? path : path.slice(0, dot);
      },

This is because x-row tag is being notified on the following path: model.#0.#1.key.

If you replace the inner repeat by:

                <template is="dom-repeat" items="[[groupData]]">
                    <x-row model="[[item]]"></x-row>
                </template>

the problem disappears.

This issue had no consequence before the #2007 fix because notifications on invalid paths were simply ignored.

@mgiuffrida

Chrome is running into this now (TypeErrors in notifyPath calls that did not previously throw an error).

There seems to be some kind of race condition where, if multiple elements reference the same object via data binding, when that object is initially set in one element, a full path for one of that object's sub-sub-sub-properties is sent via notifyPath to another element that hasn't yet received the base object.

If that makes any sense.

@david-saslawsky

My first impression is that there is a name collision between the inner template binding [[model]] which is a row and the outer property model which is a list.

I tried to pinpoint the bug around Templatizer._forwardInstanceProp or Base.notifyPath but no luck so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.