diff --git a/.changeset/silent-rocks-relax.md b/.changeset/silent-rocks-relax.md new file mode 100644 index 000000000..f32eb4f00 --- /dev/null +++ b/.changeset/silent-rocks-relax.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Prevent dev from locking up on empty selectors diff --git a/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts b/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts index dd885ffb2..a10eba77a 100644 --- a/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts +++ b/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts @@ -96,10 +96,14 @@ export function scopeRule(selector: string, className: string) { /** PostCSS Scope plugin */ export default function astroScopedStyles(options: AstroScopedOptions): Plugin { + const rulesScopedCache = new WeakSet(); return { postcssPlugin: '@astrojs/postcss-scoped-styles', Rule(rule) { - rule.selector = scopeRule(rule.selector, options.className); + if(!rulesScopedCache.has(rule)) { + rule.selector = scopeRule(rule.selector, options.className); + rulesScopedCache.add(rule); + } }, }; } diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js index 29346f043..a93e5bac0 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -40,4 +40,11 @@ Basics('Correctly serializes boolean attributes', async ({ runtime }) => { assert.equal($('h2').attr('not-data-ok'), ''); }); +Basics('Selector with an empty body', async ({ runtime }) => { + const result = await runtime.load('/empty-class'); + const html = result.contents; + const $ = doc(html); + assert.equal($('.author').length, 1, 'author class added'); +}); + Basics.run(); diff --git a/packages/astro/test/fixtures/astro-basic/src/pages/empty-class.astro b/packages/astro/test/fixtures/astro-basic/src/pages/empty-class.astro new file mode 100644 index 000000000..1dc19c7a0 --- /dev/null +++ b/packages/astro/test/fixtures/astro-basic/src/pages/empty-class.astro @@ -0,0 +1,15 @@ +--- + +--- + + + Testing + + + +
+ + \ No newline at end of file