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

fix(server): fix collect to ignore empty class #832

Merged
merged 1 commit into from Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/server/__tests__/collect.test.ts
Expand Up @@ -233,3 +233,20 @@ describe('include atrule once', () => {
test('critical', () => expect(prettyPrint(critical)).toMatchSnapshot());
test('other', () => expect(prettyPrint(other)).toMatchSnapshot());
});

describe('ignore empty class attribute', () => {
const html = dedent`
<div class=""></div>
<div class="a"></div>
<div class=""></div>
<div class="b"></div>
<div class=""></div>
`;

const css = dedent`
.not-exist {}
`;

const { critical } = collect(html, css);
test('critical should be empty', () => expect(critical).toEqual(''));
});
2 changes: 1 addition & 1 deletion packages/server/src/collect.ts
Expand Up @@ -97,7 +97,7 @@ export default function collect(html: string, css: string): CollectResult {

const extractClassesFromHtml = (html: string): RegExp => {
const htmlClasses: string[] = [];
const regex = /\s+class="([^"]*)"/gm;
const regex = /\s+class="([^"]+)"/gm;
let match = regex.exec(html);

while (match !== null) {
Expand Down