@@ -15,10 +15,14 @@ async function _update() {
1515}
1616
1717async function _updateSelectedNode ( selectedNode ) {
18- const issueListEl = document . querySelector ( "#selected ul" ) ;
19- issueListEl . innerHTML = "" ;
18+ // Get new <ul> element to avoid updating by previous rendering.
19+ const issueListEl = _getIssuesListRootElement ( "#selected ul" ) ;
2020
2121 _recursiveNodesIssuesRendering ( 0 , [ selectedNode ] , true , issueListEl , [ ] ) . then ( ( ) => {
22+ if ( ! _isCurrentlyRendering ( issueListEl ) ) {
23+ return ;
24+ }
25+
2226 if ( ! issueListEl . querySelector ( "li" ) ) {
2327 _renderNoIssue ( issueListEl ) ;
2428 }
@@ -27,7 +31,8 @@ async function _updateSelectedNode(selectedNode) {
2731
2832async function _updateSubtree ( selectedNode ) {
2933 const subtreeEl = document . getElementById ( "subtree" ) ;
30- const issueListEl = subtreeEl . querySelector ( "ul" ) ;
34+ // Get new <ul> element to avoid updating by previous rendering.
35+ const issueListEl = _getIssuesListRootElement ( "#subtree ul" ) ;
3136
3237 subtreeEl . classList . add ( "processing" ) ;
3338 const progressEl = subtreeEl . querySelector ( "aside label" ) ;
@@ -38,13 +43,36 @@ async function _updateSubtree(selectedNode) {
3843 progressEl . textContent = "Getting web compatibility issues" ;
3944 issueListEl . innerHTML = "" ;
4045 _recursiveNodesIssuesRendering ( 0 , nodesInSubtree , false , issueListEl , [ ] ) . then ( ( ) => {
46+ if ( ! _isCurrentlyRendering ( issueListEl ) ) {
47+ return ;
48+ }
49+
4150 subtreeEl . classList . remove ( "processing" ) ;
4251 if ( ! issueListEl . querySelector ( "li" ) ) {
4352 _renderNoIssue ( issueListEl ) ;
4453 }
4554 } ) ;
4655}
4756
57+ /**
58+ * Return <ul> element for the issues.
59+ * Note: This function creates new <ul> element and replaces from old <ul> element that
60+ * is matched by the given selector.
61+ *
62+ * @param {String } - selector
63+ * @return {Element } - new <ul> element that was replaced
64+ */
65+ function _getIssuesListRootElement ( selector ) {
66+ const oldElement = document . querySelector ( selector ) ;
67+ const newElement = document . createElement ( "ul" ) ;
68+ oldElement . parentElement . replaceChild ( newElement , oldElement ) ;
69+ return newElement ;
70+ }
71+
72+ function _isCurrentlyRendering ( listEl ) {
73+ return ! ! listEl . parentElement ;
74+ }
75+
4876/**
4977 * The given nodes are analysed and rendered one by one recursively.
5078 * Thus, the item of the result is appended to the given `listEl` sequentially.
@@ -63,6 +91,12 @@ async function _updateSubtree(selectedNode) {
6391 */
6492async function _recursiveNodesIssuesRendering ( index , nodes ,
6593 skipPseudo , listEl , groupsCache ) {
94+ if ( ! _isCurrentlyRendering ( listEl ) ) {
95+ // New rendering is running.
96+ listEl . remove ( ) ;
97+ return ;
98+ }
99+
66100 const node = nodes [ index ] ;
67101 if ( ! node ) {
68102 return ;
0 commit comments