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(font-display): more accurately follow CSS spec #7191

Merged
merged 4 commits into from
Feb 12, 2019

Conversation

patrickhulce
Copy link
Collaborator

Summary
One of the reasons people seem to be getting false failures is our semicolon. Thanks to @Diklla for pointing this out!

Related Issues/PRs
#6628

const rawFontDisplay = declaration.match(/font-display:(.*?);/);
// Find the font-display value by matching a single token, optionally surrounded by whitespace,
// followed either by a semicolon or the end of a block.
const rawFontDisplay = declaration.match(/font-display:(\s*\S+\s*)(;|\s*\})/);
Copy link
Member

Choose a reason for hiding this comment

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

is the last \s* not already captured by the first group?

Copy link
Member

Choose a reason for hiding this comment

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

after just getting burned by the old regex, I feel like we need some extra whitespace tests for the cases we're going to be handling now :)

Copy link
Member

Choose a reason for hiding this comment

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

+1 to @brendankenny first comment, should be:

font-display:(\s*\S+\s*)(;|\})

iirc it is valid to have white space after the property before the colon like:

font-display : 'optional';

in which case we would need:

font-display\s*:(\s*\S+\s*)(;|\})

@wardpeet
Copy link
Collaborator

wardpeet commented Feb 9, 2019

@patrickhulce do you mind adding a test where you check all possibilities from the regex?

display:  'optional'    ;
display:  'optional' }
display:  'optional'}

@patrickhulce
Copy link
Collaborator Author

patrickhulce commented Feb 11, 2019

great points everyone!

since at this point we're just taking a step back on the whole audit, I thought I'd tighten it up and make it more correct rather than the loosely goosey forgiving audit (aside from the semicolon) that it was before :)

Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

LGTM love the new changes and tests

@patrickhulce patrickhulce changed the title core(font-display): allow missing semicolon core(font-display): more accurately follow CSS-spec Feb 11, 2019
@patrickhulce patrickhulce changed the title core(font-display): more accurately follow CSS-spec core(font-display): more accurately follow CSS spec Feb 11, 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.

LGTM!

Less loose, less 🐦

// If they didn't have a font-display property, it's the default, and it's failing; bail
if (!rawFontDisplay) continue;
// If they don't have one of the passing font-display values, it's failing; bail
const hasPassingFontDisplay = PASSING_FONT_DISPLAY_REGEX.test(rawFontDisplay[0]);
const hasPassingFontDisplay = PASSING_FONT_DISPLAY_REGEX.test(rawFontDisplay[1].trim());
Copy link
Member

Choose a reason for hiding this comment

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

nit: worth keeping the whitespace in the capture group if only going to trim it?

});

it('resolves URLs relative to stylesheet URL when available', async () => {
stylesheet.header.sourceURL = 'https://cdn.example.com/foo/bar/file.css';
stylesheet.content = `
@font-face {
font-display: 'block';
font-display: block;
Copy link
Member

Choose a reason for hiding this comment

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

ha, whoops

@schoenwaldnils
Copy link

In which lighthouse version is this published?
I still get the same failing audit on this site: https://rw.schoen.world/ :/

Report: https://lighthouse-dot-webdotdevsite.appspot.com/lh/html?url=https://rw.schoen.world/

Minified styles in the head using emotion.js

@font-face{font-family:'Open Sans';font-style:normal;font-weight:300;font-display:swap;src:local('Open Sans Light'),local('OpenSans-Light'),url(https://fonts.gstatic.com/s/opensans/v16/mem5YaGs126MiZpBA-UN_r8OUuhpKKSTjw.woff2) format('woff2')}@font-face{font-family:'Open Sans';font-style:normal;font-weight:400;font-display:swap;src:local('Open Sans Regular'),local('OpenSans-Regular'),url(https://fonts.gstatic.com/s/opensans/v16/mem8YaGs126MiZpBA-UFVZ0bf8pkAg.woff2) format('woff2')}@font-face{font-family:'Open Sans';font-style:normal;font-weight:600;font-display:swap;src:local('Open Sans SemiBold'),local('OpenSans-SemiBold'),url(https://fonts.gstatic.com/s/opensans/v16/mem5YaGs126MiZpBA-UNirkOUuhpKKSTjw.woff2) format('woff2')}

@paulirish
Copy link
Member

This fix is shipping in v4.2.0+

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.

6 participants