summaryrefslogtreecommitdiff
path: root/src/compiler/optimize/postcss-scoped-styles/index.ts
diff options
context:
space:
mode:
authorGravatar Drew Powers <1369770+drwpow@users.noreply.github.com> 2021-04-02 12:50:30 -0600
committerGravatar GitHub <noreply@github.com> 2021-04-02 12:50:30 -0600
commitb58b493948ef7b6453ba8c4e94c4bd2fcaea8452 (patch)
tree4bb0426f35e3c7e6a8c7523e6f0aaa1e90407113 /src/compiler/optimize/postcss-scoped-styles/index.ts
parent004b3ea6a0b48ecc04d2a0daf9aae374983bed08 (diff)
downloadastro-b58b493948ef7b6453ba8c4e94c4bd2fcaea8452.tar.gz
astro-b58b493948ef7b6453ba8c4e94c4bd2fcaea8452.tar.zst
astro-b58b493948ef7b6453ba8c4e94c4bd2fcaea8452.zip
Fix body from being scoped (#56)
Diffstat (limited to 'src/compiler/optimize/postcss-scoped-styles/index.ts')
-rw-r--r--src/compiler/optimize/postcss-scoped-styles/index.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compiler/optimize/postcss-scoped-styles/index.ts b/src/compiler/optimize/postcss-scoped-styles/index.ts
index 0d1253350..01c0acd94 100644
--- a/src/compiler/optimize/postcss-scoped-styles/index.ts
+++ b/src/compiler/optimize/postcss-scoped-styles/index.ts
@@ -12,6 +12,9 @@ interface Selector {
const CSS_SEPARATORS = new Set([' ', ',', '+', '>', '~']);
+/** HTML tags that should never get scoped classes */
+export const NEVER_SCOPED_TAGS = new Set<string>(['base', 'body', 'font', 'frame', 'frameset', 'head', 'html', 'link', 'meta', 'noframes', 'noscript', 'script', 'style', 'title']);
+
/**
* Scope Selectors
* Given a selector string (`.btn>span,.nav>span`), add an additional CSS class to every selector (`.btn.myClass>span.myClass,.nav.myClass>span.myClass`)
@@ -62,6 +65,12 @@ export function scopeSelectors(selector: string, className: string) {
continue;
}
+ // don‘t scope body, title, etc.
+ if (NEVER_SCOPED_TAGS.has(value)) {
+ ss = head + value + tail;
+ continue;
+ }
+
// scope everything else
let newSelector = ss.substring(start, end);
const pseudoIndex = newSelector.indexOf(':');