JSON.parse issue on blaze re-render of each list


#1

Hi,

I noticed an issue where I have a list of items where each list has a button that opens a dialog, and forwards a data context.
This data context is put in a data-attribute, stringified in the helper.
When the button is clicked, the dialog opens for the data context and its context is available by accesing node.data(‘attributename’). Here it automatically gets parsed to a object.

This is where it goes wrong, if you remove elements from the list in the order:
Remove item 2
Try remove item 3

When you try to remove item 3, it gets the parsed object of number 2, which doesnt exist anymore. When you look int the source you see the correct JSON for item 3. However, the parsed object is from number 2.

If can demonstrate this issue in the test I build:

Anyone of the Blaze team who wants to take a look?


#2

If this is indeed a Meteor bug, you’re more likely to get an official response by posting it on Github.


#3

done:


#4

But what if try to use Template.currentData or Template.parentData(0)?

Template.testComponent.helpers

      dataContext: ->
        theData = Template.currentData()
        JSON.stringify( theData )

#5

that is not the point. It is not passing the correct context when the Blaze each loop re-runs.
I am just demonstrating this blaze JSON parse bug.
When you would have a persistent data collection, remove an item from the list and refresh the list, you could remove item 3 without problem. Only when you do it without renewing and the re-render is triggered, it goes awry