Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 26 commits into from
May 20, 2019

Conversation

mattzeunert
Copy link
Contributor

@mattzeunert mattzeunert commented May 15, 2019

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

Copy link
Member

@brendankenny brendankenny left a comment

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
Member

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
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
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
Member

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
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! 😎

lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
@mattzeunert
Copy link
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

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
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
Copy link
Member

@brendankenny brendankenny left a comment

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
Member

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

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
Member

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

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
Member

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
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

@@ -352,15 +352,24 @@ class DetailsRenderer {
*/
renderNode(item) {
const element = this._dom.createElement('span', 'lh-node');
if (item.nodeLabel) {
const titleEl = this._dom.createElement('div');
Copy link
Member

@brendankenny brendankenny May 17, 2019

Choose a reason for hiding this comment

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

labelEl, etc

@@ -218,6 +218,40 @@ function getNodeSelector(node) {
return parts.join(' > ');
}

/**
Copy link
Member

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
Member

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

if (title) {
return truncate(title, 80);
} else {
const nodeToUseForTitle = node.querySelector('[alt], [aria-label]');
Copy link
Member

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?)

types/audit-details.d.ts Show resolved Hide resolved
@@ -100,6 +100,8 @@
--color-white: #FFFFFF;
--color-blue-200: #90CAF9;
--color-blue-900: #0D47A1;
--color-teal-300: #00d6c1;
--color-teal-700: #008577;
Copy link
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
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
Member

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
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

Copy link
Member

@brendankenny brendankenny left a comment

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?

@@ -100,6 +100,8 @@
--color-white: #FFFFFF;
--color-blue-200: #90CAF9;
--color-blue-900: #0D47A1;
--color-teal-300: #00d6c1;
--color-teal-700: #008577;
Copy link
Member

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
Collaborator

@patrickhulce patrickhulce left a comment

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
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
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
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
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

@@ -175,6 +178,7 @@
.lh-vars.dark {
--color-red-700: var(--color-red);
--color-green-700: var(--color-green);
--color-teal-600: var(--color-cyan-500);
Copy link
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
Member

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
Copy link
Contributor Author

mattzeunert commented May 20, 2019

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

@patrickhulce
Copy link
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
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
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. 👍

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

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