{"action":"created","issue":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/1404","repository_url":"https://api.github.com/repos/lhorie/mithril.js","labels_url":"https://api.github.com/repos/lhorie/mithril.js/issues/1404/labels{/name}","comments_url":"https://api.github.com/repos/lhorie/mithril.js/issues/1404/comments","events_url":"https://api.github.com/repos/lhorie/mithril.js/issues/1404/events","html_url":"https://github.com/lhorie/mithril.js/issues/1404","id":190268218,"number":1404,"title":"[rewrite] Component recreated infinitely","user":{"login":"sixmen","id":1409279,"avatar_url":"https://avatars.githubusercontent.com/u/1409279?v=3","gravatar_id":"","url":"https://api.github.com/users/sixmen","html_url":"https://github.com/sixmen","followers_url":"https://api.github.com/users/sixmen/followers","following_url":"https://api.github.com/users/sixmen/following{/other_user}","gists_url":"https://api.github.com/users/sixmen/gists{/gist_id}","starred_url":"https://api.github.com/users/sixmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sixmen/subscriptions","organizations_url":"https://api.github.com/users/sixmen/orgs","repos_url":"https://api.github.com/users/sixmen/repos","events_url":"https://api.github.com/users/sixmen/events{/privacy}","received_events_url":"https://api.github.com/users/sixmen/received_events","type":"User","site_admin":false},"labels":[{"id":86465857,"url":"https://api.github.com/repos/lhorie/mithril.js/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-11-18T09:04:27Z","updated_at":"2016-12-03T18:50:59Z","closed_at":"2016-12-01T06:51:46Z","body":"### Description:\r\n\r\nIn Mithril 0.2.x, a component is always recreated when the route is changed,\r\nbut in rewrite, a component is not recreated if the route is same (e.x. changed from /items/1 to to /items/2), which is good in general.\r\n\r\nBut I want to recreate a component some time for freshness.\r\n\r\nI questioned to Gitter, and I got an answer to use route resolver.\r\nBut when I try it, I got a strange behavior the component is recreated infinitely.\r\n\r\n### Steps to Reproduce:\r\n\r\n```\r\nvar Item = {\r\n  oninit: function (vnode) {\r\n    vnode.state.data = 0;\r\n    m.request({\r\n      method: 'GET',\r\n      url: '/somerestapi'\r\n    }).then(function () {\r\n      vnode.state.data = vnode.attrs.id;\r\n    })\r\n  },\r\n  view: function (vnode) {\r\n    return m('div', 'Item'+vnode.attrs.id, m('br'), 'Data'+vnode.state.data, m('br'),\r\n      m('button', {onclick: function () { m.route.set('/items/' + (Number(vnode.attrs.id)+1)) }}, 'Next')\r\n    );\r\n  }\r\n};\r\n\r\nvar ItemRouteResolver = {\r\n  onmatch: function (resolve, args, requestedPath) {\r\n    resolve(Item);\r\n  },\r\n  render: function (vnode) {\r\n    vnode.key = vnode.attrs.id\r\n    return vnode;\r\n  }\r\n}\r\n\r\nm.route(document.getElementById('app'), '/items/1', {\r\n  //'/items/:id': Item\r\n  '/items/:id': ItemRouteResolver\r\n});\r\n```\r\n\r\n### Expected and Actual:\r\n\r\nI want that 'Item' and 'Data' show the same number.\r\nBut 'Data' is not changed when I does not use route resolver.\r\n\r\nAnd If I use route resolver, the browser request infinitely.\r\n(I think the chain is request done -> render -> oninit called again -> request done -> render -> ...)\r\n\r\nIs this a bug or do I need another pattern to achieve my purpose? "},"comment":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/comments/264657730","html_url":"https://github.com/lhorie/mithril.js/issues/1404#issuecomment-264657730","issue_url":"https://api.github.com/repos/lhorie/mithril.js/issues/1404","id":264657730,"user":{"login":"pygy","id":54515,"avatar_url":"https://avatars.githubusercontent.com/u/54515?v=3","gravatar_id":"","url":"https://api.github.com/users/pygy","html_url":"https://github.com/pygy","followers_url":"https://api.github.com/users/pygy/followers","following_url":"https://api.github.com/users/pygy/following{/other_user}","gists_url":"https://api.github.com/users/pygy/gists{/gist_id}","starred_url":"https://api.github.com/users/pygy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pygy/subscriptions","organizations_url":"https://api.github.com/users/pygy/orgs","repos_url":"https://api.github.com/users/pygy/repos","events_url":"https://api.github.com/users/pygy/events{/privacy}","received_events_url":"https://api.github.com/users/pygy/received_events","type":"User","site_admin":false},"created_at":"2016-12-03T18:50:59Z","updated_at":"2016-12-03T18:50:59Z","body":"I don't take it personally, but I'm not happy to see a non-trivial contribution of mine wiped out with \"fix foo\" as a commit message when it was likely a symptom, not the cause.\r\n\r\nFor context, my GitHub account is literally my CV (I hold a medical degree, I have almost never coded professionally). I'll soon start looking for a dev job, and, assuming the router was not the culprit, it is a bit of a stain although it probably doesn't matter in the larger scheme of things. However this may explain why I'm this defensive...\r\n\r\nThat being said, if you judge the current approach better (regardless of the cause of the bug) then of course you should keep it.\r\n\r\nA drawback (beside the weird internal API) is the fact that the [route matching logic](https://github.com/lhorie/mithril.js/blob/7368cf6f268825693c59caf4bfef67ef1a9bff56/router/router.js#L86-L108) runs for nothing on every redraw. No such thing with the mount-based code where redraws are the same as everywhere else, and resolution logic only runs when the router is summoned, either explicitly or implicitly by using history.\r\n\r\nOn the other hand the current code looks a bit terser than what I had, and you can probably fix the various kinks without bloating it past the size of the mount-based version."}}
{"actor":{"display_login":"pygy"}}