{"action":"created","issue":{"url":"https://api.github.com/repos/developit/preact/issues/1186","repository_url":"https://api.github.com/repos/developit/preact","labels_url":"https://api.github.com/repos/developit/preact/issues/1186/labels{/name}","comments_url":"https://api.github.com/repos/developit/preact/issues/1186/comments","events_url":"https://api.github.com/repos/developit/preact/issues/1186/events","html_url":"https://github.com/developit/preact/issues/1186","id":350738222,"node_id":"MDU6SXNzdWUzNTA3MzgyMjI=","number":1186,"title":"batched calls to setState: invalid previousState passed as this.state to shouldComponentUpdate","user":{"login":"carlhopf","id":937496,"node_id":"MDQ6VXNlcjkzNzQ5Ng==","avatar_url":"https://avatars2.githubusercontent.com/u/937496?v=4","gravatar_id":"","url":"https://api.github.com/users/carlhopf","html_url":"https://github.com/carlhopf","followers_url":"https://api.github.com/users/carlhopf/followers","following_url":"https://api.github.com/users/carlhopf/following{/other_user}","gists_url":"https://api.github.com/users/carlhopf/gists{/gist_id}","starred_url":"https://api.github.com/users/carlhopf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlhopf/subscriptions","organizations_url":"https://api.github.com/users/carlhopf/orgs","repos_url":"https://api.github.com/users/carlhopf/repos","events_url":"https://api.github.com/users/carlhopf/events{/privacy}","received_events_url":"https://api.github.com/users/carlhopf/received_events","type":"User","site_admin":false},"labels":[{"id":258981559,"node_id":"MDU6TGFiZWwyNTg5ODE1NTk=","url":"https://api.github.com/repos/developit/preact/labels/bug","name":"bug","color":"fc2929","default":true},{"id":358231498,"node_id":"MDU6TGFiZWwzNTgyMzE0OTg=","url":"https://api.github.com/repos/developit/preact/labels/important","name":"important","color":"f99157","default":false},{"id":876151250,"node_id":"MDU6TGFiZWw4NzYxNTEyNTA=","url":"https://api.github.com/repos/developit/preact/labels/pr-welcome","name":"pr-welcome","color":"54e5ab","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-08-15T09:07:45Z","updated_at":"2018-08-15T19:39:49Z","closed_at":null,"author_association":"NONE","body":"problem\r\n--------\r\n\r\n```javascript\r\nconstructor(...args) {\r\n  super(...args);\r\n  this.state.foo = 'notbar';\r\n}\r\n\r\ncomponentDidMount() {\r\n  // two calls with same value\r\n  this.setState({ foo: 'bar' });\r\n  this.setState({ foo: 'bar' });\r\n}\r\n\r\nshouldComponentUpdate(nextProps, nextState) {\r\n  return this.state.foo !== nextState.foo;\r\n}\r\n\r\n```\r\naccording to\r\n\r\nhttps://github.com/developit/preact/blob/master/src/component.js#L55\r\n\r\n1.  the first ```setState``` call updates ```this.prevState``` correctly, sets the new value to ```this.state```, and enqueues a render.\r\n\r\n2. the second ```setState``` call will update ```this.prevState``` again, **but this time also merging in the updated** ```this.state``` value from the **first** ```setState``` call.\r\n\r\nhttps://github.com/developit/preact/blob/master/src/vdom/component.js#L98\r\n\r\n3. the queued render happens and ```shouldComponentUpdate``` is invoked, with ```component.state``` set to ```component.prevState```. but ```prevState``` already is set to the value of the first ```setState``` call.\r\n\r\n4. hence, ```shouldComponentUpdate``` returns false and the queued render never happens - **although the state changed.**\r\n\r\n\r\nexpected behaviour\r\n--------------------\r\n\r\n```this.state``` in ```shouldComponentUpdate``` should be the state value from the **last** render run. even if batching multiple ```setState``` calls.\r\n\r\ntest\r\n----\r\n\r\nhttps://github.com/carlhopf/preact/commit/8695663573a7ea2d4ab2f847a56e833fe8e179fb"},"comment":{"url":"https://api.github.com/repos/developit/preact/issues/comments/413311462","html_url":"https://github.com/developit/preact/issues/1186#issuecomment-413311462","issue_url":"https://api.github.com/repos/developit/preact/issues/1186","id":413311462,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzMxMTQ2Mg==","user":{"login":"carlhopf","id":937496,"node_id":"MDQ6VXNlcjkzNzQ5Ng==","avatar_url":"https://avatars2.githubusercontent.com/u/937496?v=4","gravatar_id":"","url":"https://api.github.com/users/carlhopf","html_url":"https://github.com/carlhopf","followers_url":"https://api.github.com/users/carlhopf/followers","following_url":"https://api.github.com/users/carlhopf/following{/other_user}","gists_url":"https://api.github.com/users/carlhopf/gists{/gist_id}","starred_url":"https://api.github.com/users/carlhopf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlhopf/subscriptions","organizations_url":"https://api.github.com/users/carlhopf/orgs","repos_url":"https://api.github.com/users/carlhopf/repos","events_url":"https://api.github.com/users/carlhopf/events{/privacy}","received_events_url":"https://api.github.com/users/carlhopf/received_events","type":"User","site_admin":false},"created_at":"2018-08-15T19:39:49Z","updated_at":"2018-08-15T19:39:49Z","author_association":"NONE","body":"thanks for the quick update :) PR submitted: https://github.com/developit/preact/pull/1189"}}
{"actor":{"display_login":"carlhopf"}}