From 1215e731b8a334fce364aca77bda1085f3679e57 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Sat, 23 Jul 2022 13:11:12 -0500 Subject: [PATCH] Preserve authored CSS specificity (#4024) * feat: preserve authored CSS specificity * chore: update tests to use :where() * test: fix HTML and CSS test * test: fix imported markdown CSS test Co-authored-by: Nate Moore --- .changeset/fuzzy-donuts-wonder.md | 9 +++++++++ packages/astro/package.json | 2 +- packages/astro/test/0-css.test.js | 14 +++++++------- packages/astro/test/astro-markdown-css.test.js | 4 ++-- packages/astro/test/astro-partial-html.test.js | 2 +- pnpm-lock.yaml | 8 ++++---- 6 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 .changeset/fuzzy-donuts-wonder.md diff --git a/.changeset/fuzzy-donuts-wonder.md b/.changeset/fuzzy-donuts-wonder.md new file mode 100644 index 000000000..b31023913 --- /dev/null +++ b/.changeset/fuzzy-donuts-wonder.md @@ -0,0 +1,9 @@ +--- +'astro': patch +--- + +**BREAKING** Implement [RFC0012](https://github.com/withastro/rfcs/blob/main/proposals/0012-scoped-css-with-preserved-specificity.md) to preserve authored specificity for Astro scoped styles. + +If you use a mix of global styles and Astro scoped styles, **please visually inspect your site** after upgrading to confirm that styles are working as expected. + +If you previously relied on Astro's scoped styles to increase the specificity of your selectors, please update your selectors to use an additional class. For example, updating `div` to `div.my-class` will match the previous behavior. diff --git a/packages/astro/package.json b/packages/astro/package.json index 3e1e13fec..c8f631217 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -82,7 +82,7 @@ "test:e2e:match": "playwright test -g" }, "dependencies": { - "@astrojs/compiler": "^0.21.0", + "@astrojs/compiler": "^0.22.0", "@astrojs/language-server": "^0.20.0", "@astrojs/markdown-remark": "^0.12.0", "@astrojs/prism": "0.6.1", diff --git a/packages/astro/test/0-css.test.js b/packages/astro/test/0-css.test.js index 4b2862470..7d7000584 100644 --- a/packages/astro/test/0-css.test.js +++ b/packages/astro/test/0-css.test.js @@ -46,7 +46,7 @@ describe('CSS', function () { expect(el2.attr('class')).to.equal(`visible ${scopedClass}`); // 2. check CSS - const expected = `.blue.${scopedClass}{color:#b0e0e6}.color\\\\:blue.${scopedClass}{color:#b0e0e6}.visible.${scopedClass}{display:block}`; + const expected = `.blue:where(.${scopedClass}){color:#b0e0e6}.color\\\\:blue:where(.${scopedClass}){color:#b0e0e6}.visible:where(.${scopedClass}){display:block}`; expect(bundledCSS).to.include(expected); }); @@ -69,11 +69,11 @@ describe('CSS', function () { }); it('