Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class CriticalRequestChainRenderer {
const {file, hostname} = Util.parseURL(segment.node.request.url);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tests are failing b/c of this change. DetailsRenderer.renderTextURL tosses the host part if parsed.file === '/'. Before, the chain renderer always used the results of Util.parseURL w/o post-processing. The chain renderer now looks like this when run on the root url of a site:

image

before:

image

Copy link
Member

Choose a reason for hiding this comment

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

The chain renderer now looks like this when run on the root url of a site:

this is an improvement, IMO.

const treevalEl = dom.find('.crc-node__tree-value', chainsEl);
dom.find('.crc-node__tree-file', treevalEl).textContent = `${file}`;
dom.find('.crc-node__tree-file', treevalEl).href = segment.node.request.url;
dom.find('.crc-node__tree-hostname', treevalEl).textContent = hostname ? `(${hostname})` : '';

if (!segment.hasChildren) {
Expand Down
15 changes: 14 additions & 1 deletion lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DetailsRenderer {
}

const element = this._dom.createElement('div', 'lh-text__url');
element.appendChild(this._renderText(displayedPath));
element.appendChild(this._renderAnchor(displayedPath, url));
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like we should rename this method now ;)

maybe we can also share some logic with renderLink at this point since I was about to make _renderAnchor comments about falling back to text on invalid, etc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah, didn't see that method. done.


if (displayedHost) {
const hostElem = this._renderText(displayedHost);
Expand Down Expand Up @@ -160,6 +160,19 @@ class DetailsRenderer {
return element;
}

/**
* @param {string} text
* @param {string} href
* @return {Element}
*/
_renderAnchor(text, href) {
const element = this._dom.createElement('a', 'lh-anchor');
element.textContent = text;
element.href = href;
element.target = '_blank';
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't forget rel=noopener ;)

return element;
}

/**
* @param {string} text
* @return {Element}
Expand Down
5 changes: 5 additions & 0 deletions lighthouse-core/report/html/report-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@
object-fit: contain;
}

a.lh-anchor {
color: inherit;
text-decoration: none;
}

/* Chevron
https://codepen.io/paulirish/pen/LmzEmK
*/
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/report/html/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@

</span>
<span class="crc-node__tree-value">
<span class="crc-node__tree-file"><!-- fill me: node.request.url.file --></span>
<a class="lh-anchor crc-node__tree-file" target="_blank"><!-- fill me: node.request.url.file --></a>
<span class="crc-node__tree-hostname">(<!-- fill me: node.request.url.host -->)</span>

</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('DetailsRenderer', () => {
assert.equal(urlEl.localName, 'div');
assert.equal(urlEl.title, urlText);
assert.equal(urlEl.dataset.url, urlText);
assert.ok(urlEl.firstChild.classList.contains('lh-text'));
assert.ok(urlEl.firstChild.classList.contains('lh-anchor'));
assert.equal(urlEl.textContent, displayUrlText);
});

Expand All @@ -410,7 +410,7 @@ describe('DetailsRenderer', () => {
assert.equal(urlEl.localName, 'div');
assert.equal(urlEl.title, urlText);
assert.equal(urlEl.dataset.url, urlText);
assert.ok(urlEl.firstChild.classList.contains('lh-text'));
assert.ok(urlEl.firstChild.classList.contains('lh-anchor'));
assert.equal(urlEl.textContent, displayUrlText);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('ReportUIFeatures', () => {

function getUrlsInTable() {
return dom
.findAll('#uses-webp-images .lh-details .lh-text__url .lh-text:first-child', container)
.findAll('#uses-webp-images .lh-details .lh-text__url .lh-anchor:first-child', container)
.map(el => el.textContent);
}

Expand Down