{"action":"created","issue":{"url":"https://api.github.com/repos/chrismccord/sync/issues/178","labels_url":"https://api.github.com/repos/chrismccord/sync/issues/178/labels{/name}","comments_url":"https://api.github.com/repos/chrismccord/sync/issues/178/comments","events_url":"https://api.github.com/repos/chrismccord/sync/issues/178/events","html_url":"https://github.com/chrismccord/sync/issues/178","id":62703584,"number":178,"title":"Synced item rendered multiple times as it is updated","user":{"login":"pirkka","id":21383,"avatar_url":"https://avatars.githubusercontent.com/u/21383?v=3","gravatar_id":"","url":"https://api.github.com/users/pirkka","html_url":"https://github.com/pirkka","followers_url":"https://api.github.com/users/pirkka/followers","following_url":"https://api.github.com/users/pirkka/following{/other_user}","gists_url":"https://api.github.com/users/pirkka/gists{/gist_id}","starred_url":"https://api.github.com/users/pirkka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pirkka/subscriptions","organizations_url":"https://api.github.com/users/pirkka/orgs","repos_url":"https://api.github.com/users/pirkka/repos","events_url":"https://api.github.com/users/pirkka/events{/privacy}","received_events_url":"https://api.github.com/users/pirkka/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-18T14:10:58Z","updated_at":"2015-03-19T06:39:18Z","closed_at":"2015-03-19T06:39:18Z","body":"I've been creating a very simple chat application with threaded discussions.\r\n\r\nThe object models contains Message objects in a tree, shown in a synced list. \r\n\r\nWhen a child object is created that belongs to another message (let's call it \"OP\"), the OP is listed twice in the view. When another reply is posted, OP is now listed three times.\r\n\r\nI'm not familiar with the internals of sync gem, so I have no idea what is going on. \r\n\r\nI suspected that by using another model as a child model, I could work around this. But now that I tried saving the replies to a distinct Reply object, the same behaviour remains: whenever a Reply is created that belongs to a Message, the Message appears twice in the synced view. In this variant I'm executing \"sync_update reply.message\" to update the view after a new reply has been posted.\r\n\r\nAll symptoms disappear when page is reloaded, so this is not an issue in the underlying data model. Sync gem is somehow rendering duplicates of the same object in the list. Here's the list code:\r\n\r\n          = sync_new partial: 'message', resource: Message.new, direction: :prepend \r\n          - @messages.each do |msg|\r\n            = sync partial: 'message', resource: msg\r\n\r\nAny idea on how this might be fixed? I would love keep using sync gem as opposed to finding another solution for real-time updates. :)"},"comment":{"url":"https://api.github.com/repos/chrismccord/sync/issues/comments/83365235","html_url":"https://github.com/chrismccord/sync/issues/178#issuecomment-83365235","issue_url":"https://api.github.com/repos/chrismccord/sync/issues/178","id":83365235,"user":{"login":"pirkka","id":21383,"avatar_url":"https://avatars.githubusercontent.com/u/21383?v=3","gravatar_id":"","url":"https://api.github.com/users/pirkka","html_url":"https://github.com/pirkka","followers_url":"https://api.github.com/users/pirkka/followers","following_url":"https://api.github.com/users/pirkka/following{/other_user}","gists_url":"https://api.github.com/users/pirkka/gists{/gist_id}","starred_url":"https://api.github.com/users/pirkka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pirkka/subscriptions","organizations_url":"https://api.github.com/users/pirkka/orgs","repos_url":"https://api.github.com/users/pirkka/repos","events_url":"https://api.github.com/users/pirkka/events{/privacy}","received_events_url":"https://api.github.com/users/pirkka/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T06:39:18Z","updated_at":"2015-03-19T06:39:18Z","body":"I had taken a look at it previously, but I didn't really undestand it (I mainly looked at the code examples)... my partial looked like this:\r\n\r\n     .message{:id => \"message-#{message.id}\"} \r\n       .body \r\n         = process_message_body(message.content) if message && message.content\r\n       .replies\r\n         = message.replies.size\r\n       \r\n     .reply-form{:id => \"reply-form-#{message.id}\"}\r\n\r\nIt must have worked fine until I added the reply-form element on the same level as the message. Adding a container element fixed this in one line:\r\n\r\n      .message-container\r\n        .message{:id => \"message-#{message.id}\"} \r\n          .body \r\n            = process_message_body(message.content) if message && message.content\r\n          .replies\r\n            = message.replies.size\r\n          \r\n        .reply-form{:id => \"reply-form-#{message.id}\"}\r\n\r\nThanks for a quick reply - problem solved!\r\n\r\nWould it make sense to reword the documentation to say that the synced partial must only contain a single root level element? My malfunctioning code was \"wrapped in a root level element\" as instructed, the problem was that there were more than one root level element in the partial. Or that's how I understand it anyway :)"}}