{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/58004808","id":58004808,"diff_hunk":"@@ -1402,6 +1408,37 @@ export class Resources {\n       // Selection API not supported.\n     }\n   }\n+\n+  /**\n+   * Cleanup task queues from tasks for elements that has been unloaded.\n+   * @param resource\n+   * @private\n+   */\n+  maybeRemoveFromQueues_(resource) {\n+    if (resource.getState() == ResourceState_.NOT_LAID_OUT) {\n+      // If the layout promise for this resource has not resolved yet, remove\n+      // it from the task queues to make sure this resource can be rescheduled\n+      // for layout again later on.\n+      // TODO(mkhatib): Look into if we need to do the same for preload tasks, this\n+      // depends on whether we expect people to unload prerendered DOM.\n+      // The answer might be no since we probably want to keep the prerendered\n+      // DOM around to use as placeholder when the user navigate back to the\n+      // document.\n+      const taskId = resource.getTaskId(LAYOUT_TASK_ID_);\n+      const scheduledTask = this.queue_.getTaskById(taskId);\n+      const executingTask = this.exec_.getTaskById(taskId);\n+      if (scheduledTask && this.queue_.dequeue(scheduledTask)) {\n+        dev.fine(TAG_,\n+            'layout promise ejected from queue after unload',\n+            resource.debugid);\n+      }\n+      if (executingTask && this.exec_.dequeue(executingTask)) {\n+        dev.fine(TAG_,\n+            'layout promise ejected from exec queue after unload',\n+            resource.debugid);\n+      }\n+    }\n+  }","path":"src/service/resources-impl.js","position":null,"original_position":67,"commit_id":"47c232ed84c511401155025edc6f2e6b5ac1b44c","original_commit_id":"a620a419e24d9dd00011004663c6eb1c4f74a13b","user":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2016-03-31T06:09:55Z","updated_at":"2016-03-31T06:09:55Z","html_url":"https://github.com/ampproject/amphtml/pull/2753#discussion_r58004808","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/2753","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/58004808"},"html":{"href":"https://github.com/ampproject/amphtml/pull/2753#discussion_r58004808"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/2753"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/2753","id":64550908,"html_url":"https://github.com/ampproject/amphtml/pull/2753","diff_url":"https://github.com/ampproject/amphtml/pull/2753.diff","patch_url":"https://github.com/ampproject/amphtml/pull/2753.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/2753","number":2753,"state":"open","locked":false,"title":"Remove unloaded resources from task queues","user":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"body":"Fixes #2732 \r\n\r\ncc/ @jridgewell ","created_at":"2016-03-29T23:32:11Z","updated_at":"2016-03-31T06:09:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8a9265079c1902f4ce5051f009156970a7117df0","assignee":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/2753/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/2753/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/2753/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/47c232ed84c511401155025edc6f2e6b5ac1b44c","head":{"label":"mkhatib:remove-staled-tasks","ref":"remove-staled-tasks","sha":"47c232ed84c511401155025edc6f2e6b5ac1b44c","user":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"repo":{"id":49671997,"name":"amphtml","full_name":"mkhatib/amphtml","owner":{"login":"mkhatib","id":2647,"avatar_url":"https://avatars.githubusercontent.com/u/2647?v=3","gravatar_id":"","url":"https://api.github.com/users/mkhatib","html_url":"https://github.com/mkhatib","followers_url":"https://api.github.com/users/mkhatib/followers","following_url":"https://api.github.com/users/mkhatib/following{/other_user}","gists_url":"https://api.github.com/users/mkhatib/gists{/gist_id}","starred_url":"https://api.github.com/users/mkhatib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkhatib/subscriptions","organizations_url":"https://api.github.com/users/mkhatib/orgs","repos_url":"https://api.github.com/users/mkhatib/repos","events_url":"https://api.github.com/users/mkhatib/events{/privacy}","received_events_url":"https://api.github.com/users/mkhatib/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mkhatib/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/mkhatib/amphtml","forks_url":"https://api.github.com/repos/mkhatib/amphtml/forks","keys_url":"https://api.github.com/repos/mkhatib/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mkhatib/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mkhatib/amphtml/teams","hooks_url":"https://api.github.com/repos/mkhatib/amphtml/hooks","issue_events_url":"https://api.github.com/repos/mkhatib/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/mkhatib/amphtml/events","assignees_url":"https://api.github.com/repos/mkhatib/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/mkhatib/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/mkhatib/amphtml/tags","blobs_url":"https://api.github.com/repos/mkhatib/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mkhatib/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mkhatib/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/mkhatib/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mkhatib/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/mkhatib/amphtml/languages","stargazers_url":"https://api.github.com/repos/mkhatib/amphtml/stargazers","contributors_url":"https://api.github.com/repos/mkhatib/amphtml/contributors","subscribers_url":"https://api.github.com/repos/mkhatib/amphtml/subscribers","subscription_url":"https://api.github.com/repos/mkhatib/amphtml/subscription","commits_url":"https://api.github.com/repos/mkhatib/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/mkhatib/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/mkhatib/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/mkhatib/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/mkhatib/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/mkhatib/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mkhatib/amphtml/merges","archive_url":"https://api.github.com/repos/mkhatib/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mkhatib/amphtml/downloads","issues_url":"https://api.github.com/repos/mkhatib/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/mkhatib/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/mkhatib/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/mkhatib/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mkhatib/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/mkhatib/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/mkhatib/amphtml/deployments","created_at":"2016-01-14T20:05:58Z","updated_at":"2016-01-14T20:06:00Z","pushed_at":"2016-03-31T06:09:45Z","git_url":"git://github.com/mkhatib/amphtml.git","ssh_url":"git@github.com:mkhatib/amphtml.git","clone_url":"https://github.com/mkhatib/amphtml.git","svn_url":"https://github.com/mkhatib/amphtml","homepage":"https://ampproject.org","size":31730,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ampproject:master","ref":"master","sha":"8cacbdfb36e9b45e44812994cffceb22c7043897","user":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"repo":{"id":41766002,"name":"amphtml","full_name":"ampproject/amphtml","owner":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ampproject/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":false,"url":"https://api.github.com/repos/ampproject/amphtml","forks_url":"https://api.github.com/repos/ampproject/amphtml/forks","keys_url":"https://api.github.com/repos/ampproject/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ampproject/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ampproject/amphtml/teams","hooks_url":"https://api.github.com/repos/ampproject/amphtml/hooks","issue_events_url":"https://api.github.com/repos/ampproject/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/ampproject/amphtml/events","assignees_url":"https://api.github.com/repos/ampproject/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/ampproject/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/ampproject/amphtml/tags","blobs_url":"https://api.github.com/repos/ampproject/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ampproject/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ampproject/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ampproject/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/ampproject/amphtml/languages","stargazers_url":"https://api.github.com/repos/ampproject/amphtml/stargazers","contributors_url":"https://api.github.com/repos/ampproject/amphtml/contributors","subscribers_url":"https://api.github.com/repos/ampproject/amphtml/subscribers","subscription_url":"https://api.github.com/repos/ampproject/amphtml/subscription","commits_url":"https://api.github.com/repos/ampproject/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ampproject/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ampproject/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ampproject/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ampproject/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/ampproject/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ampproject/amphtml/merges","archive_url":"https://api.github.com/repos/ampproject/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ampproject/amphtml/downloads","issues_url":"https://api.github.com/repos/ampproject/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/ampproject/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/ampproject/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/ampproject/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ampproject/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/ampproject/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/ampproject/amphtml/deployments","created_at":"2015-09-01T22:10:53Z","updated_at":"2016-03-31T04:50:59Z","pushed_at":"2016-03-31T06:09:46Z","git_url":"git://github.com/ampproject/amphtml.git","ssh_url":"git@github.com:ampproject/amphtml.git","clone_url":"https://github.com/ampproject/amphtml.git","svn_url":"https://github.com/ampproject/amphtml","homepage":"https://ampproject.org","size":43018,"stargazers_count":7069,"watchers_count":7069,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":879,"mirror_url":null,"open_issues_count":351,"forks":879,"open_issues":351,"watchers":7069,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/2753"},"html":{"href":"https://github.com/ampproject/amphtml/pull/2753"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/2753"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/2753/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/2753/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/2753/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/47c232ed84c511401155025edc6f2e6b5ac1b44c"}}}}