Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 3 additions & 1 deletion lighthouse-core/report/html/renderer/crc-details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class CriticalRequestChainRenderer {
// Fill in url, host, and request size information.
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}`;
const fileEl = /** @type {HTMLAnchorElement} */ (dom.find('.crc-node__tree-file', treevalEl));
fileEl.textContent = `${file}`;
fileEl.href = segment.node.request.url;
dom.find('.crc-node__tree-hostname', treevalEl).textContent = hostname ? `(${hostname})` : '';

if (!segment.hasChildren) {
Expand Down
16 changes: 8 additions & 8 deletions 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._renderLink(displayedPath, new URL(url)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to move the URL construction out of _renderLink, since that's the error-prone step @patrickhulce was running into and is adding the guard against in #9067.

Can be

Suggested change
element.appendChild(this._renderLink(displayedPath, new URL(url)));
element.appendChild(this._renderLink({text: displayedPath, url}));


if (displayedHost) {
const hostElem = this._renderText(displayedHost);
Expand All @@ -130,21 +130,21 @@ class DetailsRenderer {
}

/**
* @param {LH.Audit.Details.LinkValue} details
* @param {string} text
* @param {URL} url
* @return {Element}
*/
_renderLink(details) {
_renderLink(text, url) {
const allowedProtocols = ['https:', 'http:'];
const url = new URL(details.url);
if (!allowedProtocols.includes(url.protocol)) {
// Fall back to just the link text if protocol not allowed.
return this._renderText(details.text);
return this._renderText(text);
}

const a = this._dom.createElement('a');
const a = this._dom.createElement('a', 'lh-link');
a.rel = 'noopener';
a.target = '_blank';
a.textContent = details.text;
a.textContent = text;
a.href = url.href;

return a;
Expand Down Expand Up @@ -205,7 +205,7 @@ class DetailsRenderer {
return this._renderCode(value.value);
}
case 'link': {
return this._renderLink(value);
return this._renderLink(value.text, new URL(value.url));
}
case 'node': {
return this.renderNode(value);
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-link {
color: inherit;
text-decoration: none;
}

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

</span>
<span class="crc-node__tree-value">
<span class="crc-node__tree-file"><!-- fill me: node.request.url.file --></span>
<a class="lh-link crc-node__tree-file" target="_blank"><!-- fill me: node.request.url.file --></a>
Copy link
Contributor

Choose a reason for hiding this comment

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

obviously we do need to run lighthouse against itself, also need noopener here :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

one day :)

<span class="crc-node__tree-hostname">(<!-- fill me: node.request.url.host -->)</span>

</span>
</div>
</template>
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-link'));
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-link'));
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-link:first-child', container)
.map(el => el.textContent);
}

Expand Down