From 82dc8a25a2538ea161e0dcc75febb78897109809 Mon Sep 17 00:00:00 2001 From: Ram Lmn Date: Fri, 7 Jul 2017 21:16:04 +0530 Subject: [PATCH 1/4] Prevent domify from making unecessory network requests --- src/libs/domify.js | 8 +++----- src/libs/show-names.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/domify.js b/src/libs/domify.js index 3e240b22fb8c..a5c941b16ae1 100644 --- a/src/libs/domify.js +++ b/src/libs/domify.js @@ -1,9 +1,7 @@ export default html => { - const fragment = document.createRange().createContextualFragment(html); + const fragment = document.createElement('template'); + fragment.innerHTML = html; - // If it's a single element, return just the element - if (fragment.firstChild === fragment.lastChild) { - return fragment.firstChild; - } + // Return template for querying return fragment; }; diff --git a/src/libs/show-names.js b/src/libs/show-names.js index db80112b268e..be5a115a27b4 100644 --- a/src/libs/show-names.js +++ b/src/libs/show-names.js @@ -27,7 +27,7 @@ const fetchName = async username => { export default async () => { const myUsername = getUsername(); - const cache = (await getCachedUsers())[storageKey]; + const cache = (await getCachedUsers())[storageKey] || {}; // {sindresorhus: [a.author, a.author], otheruser: [a.author]} const selector = `.js-discussion .author:not(.refined-github-fullname)`; From d332a7bc0ecfad7df654d0ccf1a5d68d4b224cf6 Mon Sep 17 00:00:00 2001 From: Ram Lmn Date: Fri, 7 Jul 2017 23:31:01 +0530 Subject: [PATCH 2/4] Only change domify --- src/libs/show-names.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/show-names.js b/src/libs/show-names.js index be5a115a27b4..db80112b268e 100644 --- a/src/libs/show-names.js +++ b/src/libs/show-names.js @@ -27,7 +27,7 @@ const fetchName = async username => { export default async () => { const myUsername = getUsername(); - const cache = (await getCachedUsers())[storageKey] || {}; + const cache = (await getCachedUsers())[storageKey]; // {sindresorhus: [a.author, a.author], otheruser: [a.author]} const selector = `.js-discussion .author:not(.refined-github-fullname)`; From 43b07c3af840b6367d75b9220e81041687708df5 Mon Sep 17 00:00:00 2001 From: Ram Lmn Date: Sat, 8 Jul 2017 08:07:11 +0530 Subject: [PATCH 3/4] Return Template.#content instead of Template for querying --- src/libs/domify.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/domify.js b/src/libs/domify.js index a5c941b16ae1..2aa807c3df98 100644 --- a/src/libs/domify.js +++ b/src/libs/domify.js @@ -2,6 +2,13 @@ export default html => { const fragment = document.createElement('template'); fragment.innerHTML = html; + const content = fragment.content; + + // If it's a single element, return just the element + if (content.firstChild === content.lastChild) { + return content.firstChild; + } + // Return template for querying - return fragment; + return content; }; From d714c04cbff326e3129fd304186ad3edcecc9b15 Mon Sep 17 00:00:00 2001 From: Ram Lmn Date: Sat, 8 Jul 2017 09:47:28 +0530 Subject: [PATCH 4/4] Fix naming of template and fragment --- src/libs/domify.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/domify.js b/src/libs/domify.js index 2aa807c3df98..de7ec271e784 100644 --- a/src/libs/domify.js +++ b/src/libs/domify.js @@ -1,14 +1,14 @@ export default html => { - const fragment = document.createElement('template'); - fragment.innerHTML = html; + const template = document.createElement('template'); + template.innerHTML = html; - const content = fragment.content; + const fragment = template.content; // If it's a single element, return just the element - if (content.firstChild === content.lastChild) { - return content.firstChild; + if (fragment.firstChild === fragment.lastChild) { + return fragment.firstChild; } - // Return template for querying - return content; + // Return fragment for querying + return fragment; };