Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(server): fix collect to ignore empty class (#832)
  • Loading branch information
cometkim committed Sep 3, 2021
1 parent a0590e5 commit 639fcca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 639fcca

Please sign in to comment.