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

Applying consecutive .splice on array of primitives with overlapping values fails #3682

Closed
3 tasks done
tomalec opened this issue May 29, 2016 · 6 comments
Closed
3 tasks done
Labels

Comments

@tomalec
Copy link
Contributor

tomalec commented May 29, 2016

Description

I try to apply .splice consecutively on same element, to alter the array of primitive values. When new value in splice is equal to any existing one (in different place), rendered result and data object gets corrupted.

Live Demo

http://jsbin.com/bimipe/edit?html,console,output

Steps to Reproduce

Example:

  1. Create a template with

    <template is="dom-repeat" items="{{array}}">
      <li>{{item}}</li>
    </template>
  2. Set model.array = [0,1]

  3. Check that you can see:

    • 0
    • 1
  4. Try to change array[0] to 1 and array[1] to 2 with splice method:

    domBind.splice("array", 0, 1, 1);
    domBind.splice("array", 1, 1, 2);

Expected Results

The DOM should be changed to reflect [1,2]:

  • 1
  • 2

Actual Results

Corrupted result is rendered:

  •  
  • 2

Browsers Affected

  • Chrome
  • Firefox
  • ? Edge
  • ? Safari 9
  • ? Safari 8
  • IE 11

Versions

  • Polymer: v1.4.0
  • webcomponents: v0.7.22

Investigation notes

  • Replacing these items with unique ones works fine

    domBind.splice("array", 0, 1, 2);
    domBind.splice("array", 1, 1, 3);
  • Calling each splice individually works:

    domBind.splice("array", 0, 1, 1);

    or

    domBind.splice("array", 1, 1, 2);
  • Calling them asynchronously works:

    domBind.splice("array", 0, 1, 1);
    setTimeout(function(){
      domBind.splice("array", 1, 1, 2);
    });
  • Even though "normalized" is not defined anywhere (Notifying consecutive array changes #2752 (comment)), when the splices are executed in anti-normalized order (last index to first), it also works

    domBind.splice("array", 1, 1, 2);
    domBind.splice("array", 0, 1, 1);

I suspect DOM binding engine thinks first 1 is the same object as one introduced in spliced and messes things up.

@warpech
Copy link

warpech commented Jun 24, 2016

+1

@miyconst
Copy link

+1

@jfrazzano
Copy link

jfrazzano commented Jun 22, 2017 via email

@warpech
Copy link

warpech commented Aug 4, 2017

This is not resolved yet.

@alshakero
Copy link
Contributor

Update: this behavior seems to be fixed in Polymer 2.x.

@TimvdLippe
Copy link
Contributor

Confirmed this has been fixed in Polymer 2: http://jsbin.com/pawopihera/edit?html,console,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants