{"action":"created","issue":{"url":"https://api.github.com/repos/raptorjs/marko-widgets/issues/16","labels_url":"https://api.github.com/repos/raptorjs/marko-widgets/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/raptorjs/marko-widgets/issues/16/comments","events_url":"https://api.github.com/repos/raptorjs/marko-widgets/issues/16/events","html_url":"https://github.com/raptorjs/marko-widgets/issues/16","id":58111186,"number":16,"title":"Conflicting Id's during partial page refresh","user":{"login":"peterdotjs","id":2185784,"avatar_url":"https://avatars.githubusercontent.com/u/2185784?v=3","gravatar_id":"","url":"https://api.github.com/users/peterdotjs","html_url":"https://github.com/peterdotjs","followers_url":"https://api.github.com/users/peterdotjs/followers","following_url":"https://api.github.com/users/peterdotjs/following{/other_user}","gists_url":"https://api.github.com/users/peterdotjs/gists{/gist_id}","starred_url":"https://api.github.com/users/peterdotjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterdotjs/subscriptions","organizations_url":"https://api.github.com/users/peterdotjs/orgs","repos_url":"https://api.github.com/users/peterdotjs/repos","events_url":"https://api.github.com/users/peterdotjs/events{/privacy}","received_events_url":"https://api.github.com/users/peterdotjs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-18T18:56:33Z","updated_at":"2015-02-18T19:22:20Z","closed_at":null,"body":"Is there a recommended way to generate unique id's for marko widgets?\r\n\r\nThe problem we are facing is when we have a partial page refresh. On the initial page load the IDs are unique. However if we partially refresh a part of the page, there will be collisions with the IDs. This is with the auto-generated IDs. \r\n\r\nWe thought of using a server side timestamp to generate the unique identifier with some namespace but even then there were collisions. \r\n\r\nAny suggestions?"},"comment":{"url":"https://api.github.com/repos/raptorjs/marko-widgets/issues/comments/74929329","html_url":"https://github.com/raptorjs/marko-widgets/issues/16#issuecomment-74929329","issue_url":"https://api.github.com/repos/raptorjs/marko-widgets/issues/16","id":74929329,"user":{"login":"patrick-steele-idem","id":978214,"avatar_url":"https://avatars.githubusercontent.com/u/978214?v=3","gravatar_id":"","url":"https://api.github.com/users/patrick-steele-idem","html_url":"https://github.com/patrick-steele-idem","followers_url":"https://api.github.com/users/patrick-steele-idem/followers","following_url":"https://api.github.com/users/patrick-steele-idem/following{/other_user}","gists_url":"https://api.github.com/users/patrick-steele-idem/gists{/gist_id}","starred_url":"https://api.github.com/users/patrick-steele-idem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrick-steele-idem/subscriptions","organizations_url":"https://api.github.com/users/patrick-steele-idem/orgs","repos_url":"https://api.github.com/users/patrick-steele-idem/repos","events_url":"https://api.github.com/users/patrick-steele-idem/events{/privacy}","received_events_url":"https://api.github.com/users/patrick-steele-idem/received_events","type":"User","site_admin":false},"created_at":"2015-02-18T19:22:20Z","updated_at":"2015-02-18T19:22:20Z","body":"Good question. This has come up before and we made some code changes to support this use case. The problem is that the server is not keeping any state and the unique IDs reset back to `0` reset for each request. As a workaround, we allow the application code to provide a \"widget ID prefix\" which is just some string that is prefixed to the auto generated ID and this prefix can be used to keep widget IDs unique across requests (assuming the application code provides an appropriate prefix).\r\n\r\nThe widget ID prefix should be provided as part of the rendering \"global\" object as shown in the following sample code:\r\n\r\n```javascript\r\ntemplate.render({\r\n        $global: {\r\n            widgetIdPrefix: 'w' + Math.random()\r\n        }\r\n    },\r\n    function(err, html) {\r\n\r\n    });\r\n```\r\n\r\nHere is the related code that is used to generate unique IDs on the server: [lib/uniqueId.js](lib/uniqueId.js)\r\n\r\nDoes that solve your problem?"}}