{"action":"closed","issue":{"url":"https://api.github.com/repos/facebook/react/issues/5219","repository_url":"https://api.github.com/repos/facebook/react","labels_url":"https://api.github.com/repos/facebook/react/issues/5219/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react/issues/5219/comments","events_url":"https://api.github.com/repos/facebook/react/issues/5219/events","html_url":"https://github.com/facebook/react/issues/5219","id":112258897,"number":5219,"title":"Proposal: Don't bail out of reconciliation for pure functions","user":{"login":"gaearon","id":810438,"avatar_url":"https://avatars.githubusercontent.com/u/810438?v=3","gravatar_id":"","url":"https://api.github.com/users/gaearon","html_url":"https://github.com/gaearon","followers_url":"https://api.github.com/users/gaearon/followers","following_url":"https://api.github.com/users/gaearon/following{/other_user}","gists_url":"https://api.github.com/users/gaearon/gists{/gist_id}","starred_url":"https://api.github.com/users/gaearon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaearon/subscriptions","organizations_url":"https://api.github.com/users/gaearon/orgs","repos_url":"https://api.github.com/users/gaearon/repos","events_url":"https://api.github.com/users/gaearon/events{/privacy}","received_events_url":"https://api.github.com/users/gaearon/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-20T00:20:57Z","updated_at":"2016-03-08T15:32:11Z","closed_at":"2016-03-08T15:32:10Z","body":"This might be a terrible idea so I'm just throwing it against the wall here.\r\n\r\nReact has a core reconciliation principle: if the `type` has changed, don't bother reconciling.\r\nFrom my understanding, it has two goals:\r\n\r\n1. It's a good heuristic because it's unlikely that two different components yield similar DOM.\r\n2. One stateful component instance can't “morph” into another component type.\r\n\r\nHowever, it makes pure function components pretty much the same pain to hot reload as class components currently are. We can't just “swap” `<ButtonBeforeEdit>` with `<ButtonAfterEdit>` because React will bail out of reconciliation and destroy any state and DOM under it as a result. This undermines the hot reloading experience in a crucial way, so we [have to keep resorting to workarounds](https://github.com/gaearon/react-proxy/pull/31#issuecomment-149377033) like [insanely complex proxies](https://github.com/gaearon/react-proxy/blob/master/src/createClassProxy.js).\r\n\r\nThe interesting thing to note about pure function components is that (2) no longer applies to them. They're stateless and have no instances right? So even if React did not bail out of reconciling different `type`s of stateless component, there would be no weird “morphing” of instances.\r\n\r\nIt would probably be less efficient in development, but we can live with that. On the other hand, making hot reloading easy with “simple tools” is beneficial because maintaining complex solutions is hard, both for me and for people who depend on my infra and have to wait for my upgrades.\r\n\r\nMaybe I'm suggesting something crazy. I'm not sure.\r\nIt certainly has important consequences outside of hot reloading or performance changes.\r\n\r\nFor example, this transition:\r\n\r\n```js\r\nconst Button = ({ children }) => <div className='button'>{children}</div>;\r\nconst Toggle = ({ children }) => <div className='toggle'>{children}</div>;\r\n\r\n<Button><StatefulThing /></Button>\r\n<Toggle><StatefulThing /></Toggle>\r\n```\r\n\r\ncurrently resets the `StatefulThing` internal state, but with the proposed change, it would not, because merely changing `Button` to `Toggle` (two stateless components) is now not, per this proposal, enough to bail out from the reconciliation.\r\n\r\nWhat do you think?"}}