Skip to content

core(report): show nodeLabel for DOM nodes in addition to snippet#8961

Merged
patrickhulce merged 26 commits into
masterfrom
show-node-text
May 20, 2019
Merged

core(report): show nodeLabel for DOM nodes in addition to snippet#8961
patrickhulce merged 26 commits into
masterfrom
show-node-text

Conversation

@mattzeunert

@mattzeunert mattzeunert commented May 15, 2019

Copy link
Copy Markdown
Contributor

Summary

Collect a human-readable title for each node and display it above the snippet.

Screenshot 2019-05-16 at 14 41 28

Related Issues/PRs

#6683

Comment thread lighthouse-core/report/html/report-styles.css Outdated
Comment thread lighthouse-core/lib/page-functions.js Outdated

@brendankenny brendankenny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice! Definitely helps give context better than the snippet alone. I wonder if there's more we could do to tie the new text and the snippet together visually, though

@@ -213,6 +214,7 @@ module.exports = [
'\n big enough target\n </a>',
'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A',
'selector': 'body > div > div > a',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add to the a11y expectations as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added details.items assertions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.

haha, uh oh, I guess I didn't know how much I was asking for :) I guess we can just cross our fingers that these are stable and all worth testing. I do really like the extra coverage this gets us

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When @mattzeunert does something, he does it right, and you get the works! 😎

Comment thread lighthouse-core/lib/page-functions.js Outdated
Comment thread lighthouse-core/lib/page-functions.js Outdated
Comment thread lighthouse-core/lib/page-functions.js
Comment thread lighthouse-core/lib/page-functions.js Outdated
Comment thread types/artifacts.d.ts Outdated
@mattzeunert

Copy link
Copy Markdown
Contributor Author

I wonder if there's more we could do to tie the new text and the snippet together visually, though

Removed some unnecessary margin between the two. Not sure what else to do exactly, @hwikyounglee any suggestions?

@hwikyounglee

Copy link
Copy Markdown

I wonder if there's more we could do to tie the new text and the snippet together visually, though

Removed some unnecessary margin between the two. Not sure what else to do exactly, @hwikyounglee any suggestions?

Thanks Matt. Only thing I would double check is the contrast of the green text on gray and on white. We need to aim for 4.5 at minimum.

@yuinchien for any further guidance

@mattzeunert

Copy link
Copy Markdown
Contributor Author

Only thing I would double check is the contrast of the green text on gray and on white. We need to aim for 4.5 at minimum.

Good point. We weren't using a var for it before, using --color-green-700 for now:

Screenshot 2019-05-16 at 17 11 54

@mattzeunert mattzeunert changed the title core(report): show title for DOM nodes in addition to snippet core(report): show nodeLabel for DOM nodes in addition to snippet May 17, 2019

@brendankenny brendankenny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks great. Last nits

@@ -213,6 +214,7 @@ module.exports = [
'\n big enough target\n </a>',
'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A',
'selector': 'body > div > div > a',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.

haha, uh oh, I guess I didn't know how much I was asking for :) I guess we can just cross our fingers that these are stable and all worth testing. I do really like the extra coverage this gets us

Comment thread lighthouse-core/lib/page-functions.js Outdated
function getNodeLabel(node) {
const tagName = node.tagName.toLowerCase();
if (tagName !== 'html' && tagName !== 'body') {
const title = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not a big deal, but I guess s/title/label

Comment thread lighthouse-core/lib/page-functions.js Outdated
function getNodeLabel(node) {
const tagName = node.tagName.toLowerCase();
if (tagName !== 'html' && tagName !== 'body') {
const title = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also should use the standard node.textContent (unless innerText was intentional?)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I specifically requested innerText because textContent gets us all that inline script instead of actual text

renderNode(item) {
const element = this._dom.createElement('span', 'lh-node');
if (item.nodeLabel) {
const titleEl = this._dom.createElement('div');

@brendankenny brendankenny May 17, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

labelEl, etc

Comment thread lighthouse-core/test/lib/page-functions-test.js
return parts.join(' > ');
}

/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add a comment for this function? Basically trying to provide a human recognizable label for the given element. Falls back to the tagName if no useful label is found.

/* istanbul ignore next */
function getNodeLabel(node) {
const tagName = node.tagName.toLowerCase();
if (tagName !== 'html' && tagName !== 'body') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add back that comment about why we skip html and body

Comment thread lighthouse-core/lib/page-functions.js Outdated
if (title) {
return truncate(title, 80);
} else {
const nodeToUseForTitle = node.querySelector('[alt], [aria-label]');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe add comment about why it's useful to recursively search (what cases does this help with?)

Comment thread types/audit-details.d.ts
Comment thread lighthouse-core/test/lib/page-functions-test.js
--color-blue-200: #90CAF9;
--color-blue-900: #0D47A1;
--color-teal-300: #00d6c1;
--color-teal-700: #008577;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-introduced teal since it was a bit nicer than the green. Do the numbers at the end have a specific meaning, other than broadly identifying darkness?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's the shade in the material design color palette https://material.io/design/color/#

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this the right number, then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed it to use material design colors.

Also cut the snippet line height a bit.

Screenshot 2019-05-20 at 20 31 26

Screenshot 2019-05-20 at 20 31 33

@brendankenny brendankenny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@patrickhulce do you want to take another look?

--color-blue-200: #90CAF9;
--color-blue-900: #0D47A1;
--color-teal-300: #00d6c1;
--color-teal-700: #008577;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this the right number, then?

@patrickhulce patrickhulce left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't love the truncate situation, but I won't block an otherwise approved merge because of it either.

I'll just pick "Comment" instead :)

LGTM otherwise!

@@ -213,6 +214,7 @@ module.exports = [
'\n big enough target\n </a>',
'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A',
'selector': 'body > div > div > a',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When @mattzeunert does something, he does it right, and you get the works! 😎

if (tagName !== 'html' && tagName !== 'body') {
const nodeLabel = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label');
if (nodeLabel) {
return truncate(nodeLabel, 80);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was making this comment over in #8979 , but it's unfortunate when page-functions in a lib have dependencies on each other that you have to know about ahead of time.

since it's basically a single ternary line WDYT about copying the function definition in the two files instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are you thinking have it in tap-targets.js and also inlined inside getNodeLabel?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah that was my thought

.lh-vars.dark {
--color-red-700: var(--color-red);
--color-green-700: var(--color-green);
--color-teal-600: var(--color-cyan-500);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dark mode is weird o.O

@brendankenny

Copy link
Copy Markdown
Contributor

I don't love the truncate situation, but I won't block an otherwise approved merge because of it either.

I was making this comment over in #8979 , but it's unfortunate when page-functions in a lib have dependencies on each other that you have to know about ahead of time.

with this, tap-targets, iframeelements, and...other stuff(?) making changes to page-functions in current PRs, my vote is definitely to make things simple rather than have to come back later and try to untangle (which will be really hard because debugging evaluateAsync functions in gatherers is really hard)

@mattzeunert

mattzeunert commented May 20, 2019

Copy link
Copy Markdown
Contributor Author

Maybe the exported fnString shouldn't just be fn.toString() but also all its dependencies?

@patrickhulce

Copy link
Copy Markdown
Collaborator

Maybe the exported fnString shouldn't just be fn.toString() but also all its dependencies?

Yeah that's a good idea, though perhaps dupes might be an issue then? Since the function is so simple here I think inline is decent option, but we'll have to figure this out long-term for sure either.

@mattzeunert

Copy link
Copy Markdown
Contributor Author

Maybe the exported fnString shouldn't just be fn.toString() but also all its dependencies?

Yeah that's a good idea, though perhaps dupes might be an issue then? Since the function is so simple here I think inline is decent option, but we'll have to figure this out long-term for sure either.

Is there an issue with dupes other than aesthetics? There'd be a perf impact but that seems very minor.

@patrickhulce

Copy link
Copy Markdown
Collaborator

Is there an issue with dupes other than aesthetics?

I was thinking of variable declarations not function declarations, but I suppose all our dupes would be of function declarations, so it's a non-issue. 👍

@patrickhulce patrickhulce left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Thanks @mattzeunert for the fix! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants