Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Prevent domify from making unnecessary network requests - #582

Merged
fregante merged 4 commits into
refined-github:masterfrom
ramlmn:fix-domify
Jul 8, 2017
Merged

Prevent domify from making unnecessary network requests#582
fregante merged 4 commits into
refined-github:masterfrom
ramlmn:fix-domify

Conversation

@ramlmn

@ramlmn ramlmn commented Jul 7, 2017

Copy link
Copy Markdown

document.createRange().createContextualFragment helps in creating a document fragment by parsing HTML but additionally loads resources linked from the HTML.

This is solved by using the HTML template tag.

@ramlmn

ramlmn commented Jul 7, 2017

Copy link
Copy Markdown
Author

And presumably solves possible issue mentioned in this comment.

Comment thread src/libs/show-names.js
export default async () => {
const myUsername = getUsername();
const cache = (await getCachedUsers())[storageKey] || {};
const cache = (await getCachedUsers())[storageKey];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right:

screen shot 2017-07-08 at 03 48 02

However this PR changes the return.

fragment is currently the template element itself; it needs to be a fragment or the requested element.

  1. Use el.content to access its fragment.
  2. Retain lines 4-7 because one element needs to be returned as one element, not as a fragment

@ramlmn

ramlmn commented Jul 8, 2017

Copy link
Copy Markdown
Author

@bfred-it Can you review the changes?

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable fragment is an element and the variable content is a fragment, can you fix the naming?

Also the last comment mentions returning the template but it's actually returning the fragment.

@ramlmn

ramlmn commented Jul 8, 2017

Copy link
Copy Markdown
Author
export default html => {
	const template = document.createElement('template');
	template.innerHTML = html;

	const fragment = template.content;

	// If it's a single element, return just the element
	if (fragment.firstChild === fragment.lastChild) {
		return fragment.firstChild;
	}

	// Return fragment for querying
	return fragment; // <-- Should this be `fragment` or `template`?
};

@bfred-it Is this good enough?

@fregante

fregante commented Jul 8, 2017

Copy link
Copy Markdown
Member

Yep! That'd be good! The last line is return fragment like it originally was.

@ramlmn

ramlmn commented Jul 8, 2017

Copy link
Copy Markdown
Author

Fixed it!

@fregante
fregante merged commit 9359bc1 into refined-github:master Jul 8, 2017
@fregante

fregante commented Jul 8, 2017

Copy link
Copy Markdown
Member

Excellent! I tested this in show-names (currently the only place where it's used)

About #581 (comment): feel free to open issues when you encounter possible bugs. Sometimes it's hard to focus on one discussion if unrelated requests mix in.

@ramlmn

ramlmn commented Jul 8, 2017

Copy link
Copy Markdown
Author

#591 solves #581 (comment)

@ramlmn
ramlmn deleted the fix-domify branch July 8, 2017 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants