Skip to content
Permalink
Browse files
fix(server): fix collect to ignore empty class (#832)
  • Loading branch information
cometkim committed Sep 3, 2021
1 parent a0590e5 commit 639fccae7f814eaa2714354aaa516a85cc8c4ebf
Showing with 18 additions and 1 deletion.
  1. +17 −0 packages/server/__tests__/collect.test.ts
  2. +1 −1 packages/server/src/collect.ts
@@ -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(''));
});
@@ -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) {

0 comments on commit 639fcca

Please sign in to comment.