{"action":"created","comment":{"url":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments/215702642","pull_request_review_id":153027538,"id":215702642,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNTcwMjY0Mg==","diff_hunk":"@@ -13,67 +13,59 @@ import { parse } from '@wordpress/blocks';\n import { withSelect, withDispatch } from '@wordpress/data';\n import { withInstanceId, compose } from '@wordpress/compose';\n \n-/**\n- * Returns the PostTextEditor state given a set of props.\n- *\n- * @param {Object} props Component props.\n- *\n- * @return {Object} State object.\n- */\n-function computeDerivedState( props ) {\n-\treturn {\n-\t\tpersistedValue: props.value,\n-\t\tvalue: props.value,\n-\t\tisDirty: false,\n-\t};\n-}\n-\n-class PostTextEditor extends Component {\n+export class PostTextEditor extends Component {\n \tconstructor() {\n \t\tsuper( ...arguments );\n \n-\t\tthis.startEditing = this.startEditing.bind( this );\n \t\tthis.edit = this.edit.bind( this );\n \t\tthis.stopEditing = this.stopEditing.bind( this );\n \n-\t\tthis.state = {\n-\t\t\tvalue: null,\n-\t\t\tisDirty: false,\n-\t\t};\n+\t\tthis.state = {};\n \t}\n \n-\tstatic getDerivedPropsFromState( props, state ) {\n-\t\t// If we receive a new value while we're editing (but before we've made\n-\t\t// changes), go ahead and clobber the local state\n-\t\tif ( state.persistedValue !== props.value && ! state.isDirty ) {\n-\t\t\treturn computeDerivedState( props );\n+\tstatic getDerivedStateFromProps( props, state ) {\n+\t\tif ( state.isDirty ) {\n+\t\t\treturn null;\n \t\t}\n \n-\t\treturn null;\n-\t}\n-\n-\tstartEditing() {\n-\t\t// Copying the post content into local state ensures that edits won't be\n-\t\t// clobbered by changes to global editor state\n-\t\tthis.setState( { value: this.props.value } );\n+\t\treturn {\n+\t\t\tvalue: props.value,\n+\t\t\tisDirty: false,\n+\t\t};\n \t}\n \n+\t/**\n+\t * Handles a textarea change event to notify the onChange prop callback and\n+\t * reflect the new value in the component's own state. This marks the start\n+\t * of the user's edits, if not already changed, preventing future props\n+\t * changes to value from replacing the rendered value. This is expected to\n+\t * be followed by a reset to dirty state via `stopEditing`.\n+\t *\n+\t * @see stopEditing\n+\t *\n+\t * @param {Event} event Change event.\n+\t */\n \tedit( event ) {\n \t\tconst value = event.target.value;\n \t\tthis.props.onChange( value );","path":"packages/editor/src/components/post-text-editor/index.js","position":71,"original_position":71,"commit_id":"3b2444e29cdc5ea44e26ff83fe71775b0e81ca72","original_commit_id":"3b2444e29cdc5ea44e26ff83fe71775b0e81ca72","user":{"login":"aduth","id":1779930,"node_id":"MDQ6VXNlcjE3Nzk5MzA=","avatar_url":"https://avatars1.githubusercontent.com/u/1779930?v=4","gravatar_id":"","url":"https://api.github.com/users/aduth","html_url":"https://github.com/aduth","followers_url":"https://api.github.com/users/aduth/followers","following_url":"https://api.github.com/users/aduth/following{/other_user}","gists_url":"https://api.github.com/users/aduth/gists{/gist_id}","starred_url":"https://api.github.com/users/aduth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduth/subscriptions","organizations_url":"https://api.github.com/users/aduth/orgs","repos_url":"https://api.github.com/users/aduth/repos","events_url":"https://api.github.com/users/aduth/events{/privacy}","received_events_url":"https://api.github.com/users/aduth/received_events","type":"User","site_admin":false},"body":"Can you elaborate on what's weird here? `onChange` is called to surface the edit to the editor store immediately (so as to mark for dirty detection).","created_at":"2018-09-06T16:58:47Z","updated_at":"2018-09-06T16:58:47Z","html_url":"https://github.com/WordPress/gutenberg/pull/9513#discussion_r215702642","pull_request_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments/215702642"},"html":{"href":"https://github.com/WordPress/gutenberg/pull/9513#discussion_r215702642"},"pull_request":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513"}},"in_reply_to_id":214593909},"pull_request":{"url":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513","id":212416620,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyNDE2NjIw","html_url":"https://github.com/WordPress/gutenberg/pull/9513","diff_url":"https://github.com/WordPress/gutenberg/pull/9513.diff","patch_url":"https://github.com/WordPress/gutenberg/pull/9513.patch","issue_url":"https://api.github.com/repos/WordPress/gutenberg/issues/9513","number":9513,"state":"closed","locked":false,"title":"Editor: PostTextEditor: Fix case where empty state value defers to prop","user":{"login":"aduth","id":1779930,"node_id":"MDQ6VXNlcjE3Nzk5MzA=","avatar_url":"https://avatars1.githubusercontent.com/u/1779930?v=4","gravatar_id":"","url":"https://api.github.com/users/aduth","html_url":"https://github.com/aduth","followers_url":"https://api.github.com/users/aduth/followers","following_url":"https://api.github.com/users/aduth/following{/other_user}","gists_url":"https://api.github.com/users/aduth/gists{/gist_id}","starred_url":"https://api.github.com/users/aduth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduth/subscriptions","organizations_url":"https://api.github.com/users/aduth/orgs","repos_url":"https://api.github.com/users/aduth/repos","events_url":"https://api.github.com/users/aduth/events{/privacy}","received_events_url":"https://api.github.com/users/aduth/received_events","type":"User","site_admin":false},"body":"Extracted from #9403\r\n\r\nThis pull request seeks to fix a bug with PostTextEditor where intended state value is not always reflected in the rendered textarea when empty. Since previously, it relied on a simple truthy condition to determine whether to use state or props value, if the user had erased all content from the textarea, it would effectively trigger this fallback to props value to occur, thus disregarding the local (user-intended) state.\r\n\r\nIn practice, this had no effect only because props edit state was kept in sync, so the value remained the same. The issue became more obvious through related refactoring in #9403.\r\n\r\n**Testing instructions:**\r\n\r\nThere should be no regressions in the behavior of the PostTextEditor.\r\n\r\nEnsure unit tests pass:\r\n\r\n```\r\nnpm run test-unit editor/src/components/post-text-editor/test/index.js\r\n```\r\n\r\n**Future tasks:**\r\n\r\nIn testing this myself, I discovered some unfortunate consequences of our \"delayed sync\" blocks parsing behavior. Since we rely on the `blur` event to persist content, the sync doesn't always occur, for example when using the keyboard shortcut to switch between modes. I created an issue at #9512 to track (with potential fix included).","created_at":"2018-08-31T15:19:19Z","updated_at":"2018-09-06T16:58:47Z","closed_at":"2018-09-03T09:08:42Z","merged_at":"2018-09-03T09:08:42Z","merge_commit_sha":"71c4d8f217aa809e598cb4399a4fcaf81feea964","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":643827428,"node_id":"MDU6TGFiZWw2NDM4Mjc0Mjg=","url":"https://api.github.com/repos/WordPress/gutenberg/labels/Code%20Editor","name":"Code Editor","color":"bfdadc","default":false},{"id":531680823,"node_id":"MDU6TGFiZWw1MzE2ODA4MjM=","url":"https://api.github.com/repos/WordPress/gutenberg/labels/[Type]%20Bug","name":"[Type] Bug","color":"d93f0b","default":false}],"milestone":{"url":"https://api.github.com/repos/WordPress/gutenberg/milestones/63","html_url":"https://github.com/WordPress/gutenberg/milestone/63","labels_url":"https://api.github.com/repos/WordPress/gutenberg/milestones/63/labels","id":3584407,"node_id":"MDk6TWlsZXN0b25lMzU4NDQwNw==","number":63,"title":"3.8","description":"","creator":{"login":"mtias","id":548849,"node_id":"MDQ6VXNlcjU0ODg0OQ==","avatar_url":"https://avatars2.githubusercontent.com/u/548849?v=4","gravatar_id":"","url":"https://api.github.com/users/mtias","html_url":"https://github.com/mtias","followers_url":"https://api.github.com/users/mtias/followers","following_url":"https://api.github.com/users/mtias/following{/other_user}","gists_url":"https://api.github.com/users/mtias/gists{/gist_id}","starred_url":"https://api.github.com/users/mtias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtias/subscriptions","organizations_url":"https://api.github.com/users/mtias/orgs","repos_url":"https://api.github.com/users/mtias/repos","events_url":"https://api.github.com/users/mtias/events{/privacy}","received_events_url":"https://api.github.com/users/mtias/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":39,"state":"open","created_at":"2018-08-20T17:39:34Z","updated_at":"2018-09-06T14:59:50Z","due_on":"2018-09-06T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513/commits","review_comments_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513/comments","review_comment_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WordPress/gutenberg/issues/9513/comments","statuses_url":"https://api.github.com/repos/WordPress/gutenberg/statuses/3b2444e29cdc5ea44e26ff83fe71775b0e81ca72","head":{"label":"WordPress:fix/post-text-editor-local-state","ref":"fix/post-text-editor-local-state","sha":"3b2444e29cdc5ea44e26ff83fe71775b0e81ca72","user":{"login":"WordPress","id":276006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NjAwNg==","avatar_url":"https://avatars0.githubusercontent.com/u/276006?v=4","gravatar_id":"","url":"https://api.github.com/users/WordPress","html_url":"https://github.com/WordPress","followers_url":"https://api.github.com/users/WordPress/followers","following_url":"https://api.github.com/users/WordPress/following{/other_user}","gists_url":"https://api.github.com/users/WordPress/gists{/gist_id}","starred_url":"https://api.github.com/users/WordPress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WordPress/subscriptions","organizations_url":"https://api.github.com/users/WordPress/orgs","repos_url":"https://api.github.com/users/WordPress/repos","events_url":"https://api.github.com/users/WordPress/events{/privacy}","received_events_url":"https://api.github.com/users/WordPress/received_events","type":"Organization","site_admin":false},"repo":{"id":80862584,"node_id":"MDEwOlJlcG9zaXRvcnk4MDg2MjU4NA==","name":"gutenberg","full_name":"WordPress/gutenberg","owner":{"login":"WordPress","id":276006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NjAwNg==","avatar_url":"https://avatars0.githubusercontent.com/u/276006?v=4","gravatar_id":"","url":"https://api.github.com/users/WordPress","html_url":"https://github.com/WordPress","followers_url":"https://api.github.com/users/WordPress/followers","following_url":"https://api.github.com/users/WordPress/following{/other_user}","gists_url":"https://api.github.com/users/WordPress/gists{/gist_id}","starred_url":"https://api.github.com/users/WordPress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WordPress/subscriptions","organizations_url":"https://api.github.com/users/WordPress/orgs","repos_url":"https://api.github.com/users/WordPress/repos","events_url":"https://api.github.com/users/WordPress/events{/privacy}","received_events_url":"https://api.github.com/users/WordPress/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WordPress/gutenberg","description":"Printing since 1440. Development hub for the editor focus in core. Plugin is available from the official WordPress repository.","fork":false,"url":"https://api.github.com/repos/WordPress/gutenberg","forks_url":"https://api.github.com/repos/WordPress/gutenberg/forks","keys_url":"https://api.github.com/repos/WordPress/gutenberg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WordPress/gutenberg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WordPress/gutenberg/teams","hooks_url":"https://api.github.com/repos/WordPress/gutenberg/hooks","issue_events_url":"https://api.github.com/repos/WordPress/gutenberg/issues/events{/number}","events_url":"https://api.github.com/repos/WordPress/gutenberg/events","assignees_url":"https://api.github.com/repos/WordPress/gutenberg/assignees{/user}","branches_url":"https://api.github.com/repos/WordPress/gutenberg/branches{/branch}","tags_url":"https://api.github.com/repos/WordPress/gutenberg/tags","blobs_url":"https://api.github.com/repos/WordPress/gutenberg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WordPress/gutenberg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WordPress/gutenberg/git/refs{/sha}","trees_url":"https://api.github.com/repos/WordPress/gutenberg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WordPress/gutenberg/statuses/{sha}","languages_url":"https://api.github.com/repos/WordPress/gutenberg/languages","stargazers_url":"https://api.github.com/repos/WordPress/gutenberg/stargazers","contributors_url":"https://api.github.com/repos/WordPress/gutenberg/contributors","subscribers_url":"https://api.github.com/repos/WordPress/gutenberg/subscribers","subscription_url":"https://api.github.com/repos/WordPress/gutenberg/subscription","commits_url":"https://api.github.com/repos/WordPress/gutenberg/commits{/sha}","git_commits_url":"https://api.github.com/repos/WordPress/gutenberg/git/commits{/sha}","comments_url":"https://api.github.com/repos/WordPress/gutenberg/comments{/number}","issue_comment_url":"https://api.github.com/repos/WordPress/gutenberg/issues/comments{/number}","contents_url":"https://api.github.com/repos/WordPress/gutenberg/contents/{+path}","compare_url":"https://api.github.com/repos/WordPress/gutenberg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WordPress/gutenberg/merges","archive_url":"https://api.github.com/repos/WordPress/gutenberg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WordPress/gutenberg/downloads","issues_url":"https://api.github.com/repos/WordPress/gutenberg/issues{/number}","pulls_url":"https://api.github.com/repos/WordPress/gutenberg/pulls{/number}","milestones_url":"https://api.github.com/repos/WordPress/gutenberg/milestones{/number}","notifications_url":"https://api.github.com/repos/WordPress/gutenberg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WordPress/gutenberg/labels{/name}","releases_url":"https://api.github.com/repos/WordPress/gutenberg/releases{/id}","deployments_url":"https://api.github.com/repos/WordPress/gutenberg/deployments","created_at":"2017-02-03T19:34:19Z","updated_at":"2018-09-06T15:18:59Z","pushed_at":"2018-09-06T16:55:38Z","git_url":"git://github.com/WordPress/gutenberg.git","ssh_url":"git@github.com:WordPress/gutenberg.git","clone_url":"https://github.com/WordPress/gutenberg.git","svn_url":"https://github.com/WordPress/gutenberg","homepage":"https://wordpress.org/plugins/gutenberg/","size":22415,"stargazers_count":3224,"watchers_count":3224,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":858,"mirror_url":null,"archived":false,"open_issues_count":1388,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":858,"open_issues":1388,"watchers":3224,"default_branch":"master"}},"base":{"label":"WordPress:master","ref":"master","sha":"6a5ac6ae0b2cfe9308234026c329b3d51f7e2349","user":{"login":"WordPress","id":276006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NjAwNg==","avatar_url":"https://avatars0.githubusercontent.com/u/276006?v=4","gravatar_id":"","url":"https://api.github.com/users/WordPress","html_url":"https://github.com/WordPress","followers_url":"https://api.github.com/users/WordPress/followers","following_url":"https://api.github.com/users/WordPress/following{/other_user}","gists_url":"https://api.github.com/users/WordPress/gists{/gist_id}","starred_url":"https://api.github.com/users/WordPress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WordPress/subscriptions","organizations_url":"https://api.github.com/users/WordPress/orgs","repos_url":"https://api.github.com/users/WordPress/repos","events_url":"https://api.github.com/users/WordPress/events{/privacy}","received_events_url":"https://api.github.com/users/WordPress/received_events","type":"Organization","site_admin":false},"repo":{"id":80862584,"node_id":"MDEwOlJlcG9zaXRvcnk4MDg2MjU4NA==","name":"gutenberg","full_name":"WordPress/gutenberg","owner":{"login":"WordPress","id":276006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NjAwNg==","avatar_url":"https://avatars0.githubusercontent.com/u/276006?v=4","gravatar_id":"","url":"https://api.github.com/users/WordPress","html_url":"https://github.com/WordPress","followers_url":"https://api.github.com/users/WordPress/followers","following_url":"https://api.github.com/users/WordPress/following{/other_user}","gists_url":"https://api.github.com/users/WordPress/gists{/gist_id}","starred_url":"https://api.github.com/users/WordPress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WordPress/subscriptions","organizations_url":"https://api.github.com/users/WordPress/orgs","repos_url":"https://api.github.com/users/WordPress/repos","events_url":"https://api.github.com/users/WordPress/events{/privacy}","received_events_url":"https://api.github.com/users/WordPress/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WordPress/gutenberg","description":"Printing since 1440. Development hub for the editor focus in core. Plugin is available from the official WordPress repository.","fork":false,"url":"https://api.github.com/repos/WordPress/gutenberg","forks_url":"https://api.github.com/repos/WordPress/gutenberg/forks","keys_url":"https://api.github.com/repos/WordPress/gutenberg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WordPress/gutenberg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WordPress/gutenberg/teams","hooks_url":"https://api.github.com/repos/WordPress/gutenberg/hooks","issue_events_url":"https://api.github.com/repos/WordPress/gutenberg/issues/events{/number}","events_url":"https://api.github.com/repos/WordPress/gutenberg/events","assignees_url":"https://api.github.com/repos/WordPress/gutenberg/assignees{/user}","branches_url":"https://api.github.com/repos/WordPress/gutenberg/branches{/branch}","tags_url":"https://api.github.com/repos/WordPress/gutenberg/tags","blobs_url":"https://api.github.com/repos/WordPress/gutenberg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WordPress/gutenberg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WordPress/gutenberg/git/refs{/sha}","trees_url":"https://api.github.com/repos/WordPress/gutenberg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WordPress/gutenberg/statuses/{sha}","languages_url":"https://api.github.com/repos/WordPress/gutenberg/languages","stargazers_url":"https://api.github.com/repos/WordPress/gutenberg/stargazers","contributors_url":"https://api.github.com/repos/WordPress/gutenberg/contributors","subscribers_url":"https://api.github.com/repos/WordPress/gutenberg/subscribers","subscription_url":"https://api.github.com/repos/WordPress/gutenberg/subscription","commits_url":"https://api.github.com/repos/WordPress/gutenberg/commits{/sha}","git_commits_url":"https://api.github.com/repos/WordPress/gutenberg/git/commits{/sha}","comments_url":"https://api.github.com/repos/WordPress/gutenberg/comments{/number}","issue_comment_url":"https://api.github.com/repos/WordPress/gutenberg/issues/comments{/number}","contents_url":"https://api.github.com/repos/WordPress/gutenberg/contents/{+path}","compare_url":"https://api.github.com/repos/WordPress/gutenberg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WordPress/gutenberg/merges","archive_url":"https://api.github.com/repos/WordPress/gutenberg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WordPress/gutenberg/downloads","issues_url":"https://api.github.com/repos/WordPress/gutenberg/issues{/number}","pulls_url":"https://api.github.com/repos/WordPress/gutenberg/pulls{/number}","milestones_url":"https://api.github.com/repos/WordPress/gutenberg/milestones{/number}","notifications_url":"https://api.github.com/repos/WordPress/gutenberg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WordPress/gutenberg/labels{/name}","releases_url":"https://api.github.com/repos/WordPress/gutenberg/releases{/id}","deployments_url":"https://api.github.com/repos/WordPress/gutenberg/deployments","created_at":"2017-02-03T19:34:19Z","updated_at":"2018-09-06T15:18:59Z","pushed_at":"2018-09-06T16:55:38Z","git_url":"git://github.com/WordPress/gutenberg.git","ssh_url":"git@github.com:WordPress/gutenberg.git","clone_url":"https://github.com/WordPress/gutenberg.git","svn_url":"https://github.com/WordPress/gutenberg","homepage":"https://wordpress.org/plugins/gutenberg/","size":22415,"stargazers_count":3224,"watchers_count":3224,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":858,"mirror_url":null,"archived":false,"open_issues_count":1388,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":858,"open_issues":1388,"watchers":3224,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513"},"html":{"href":"https://github.com/WordPress/gutenberg/pull/9513"},"issue":{"href":"https://api.github.com/repos/WordPress/gutenberg/issues/9513"},"comments":{"href":"https://api.github.com/repos/WordPress/gutenberg/issues/9513/comments"},"review_comments":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513/comments"},"review_comment":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/9513/commits"},"statuses":{"href":"https://api.github.com/repos/WordPress/gutenberg/statuses/3b2444e29cdc5ea44e26ff83fe71775b0e81ca72"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"aduth"}}