Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix body scoping #1130

Merged
merged 1 commit into from
Aug 16, 2021
Merged

Fix body scoping #1130

merged 1 commit into from
Aug 16, 2021

Conversation

drwpow
Copy link
Member

@drwpow drwpow commented Aug 16, 2021

Changes

Fixes #1074. In certain situations, our CSS scoping would encounter unexpected characters and scope classes unnecessarily (like body). This PR adds better css sanitization

Testing

Test added.

Docs

Bugfix; no docs needed.

@changeset-bot
Copy link

changeset-bot bot commented Aug 16, 2021

🦋 Changeset detected

Latest commit: 71b8156

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

astro-www – ./www

🔍 Inspect: https://vercel.com/pikapkg/astro-www/Arq2oPmx4humYHiwC5q2Do4xUQCt
✅ Preview: Canceled

[Deployment for 71b8156 canceled]

astro-docs – ./docs

🔍 Inspect: https://vercel.com/pikapkg/astro-docs/8Lbo56xWCyrhDoRq7VzcWPLT3qLg
✅ Preview: https://astro-docs-git-fix-body-scoping-pikapkg.vercel.app

@@ -13,6 +13,11 @@ interface Selector {
const CSS_SEPARATORS = new Set([' ', ',', '+', '>', '~']);
const KEYFRAME_PERCENT = /\d+\.?\d*%/;

/** minify selector CSS */
function minifySelector(selector: string): string {
return selector.replace(/(\r?\n|\s)+/g, ' ').replace(/\s*(,|\+|>|~|\(|\))\s*/g, '$1');
Copy link
Member Author

@drwpow drwpow Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change here is CSS sanitization. This removes any extraneous whitespace characters (including linebreaks) that aren’t essential to the CSS selector (keeping in mind that some whitespace is essential as child selector, but other whitespace is non-essential such as .foo + \n .bar and can be removed).

The issue was whitespace not being handled properly, resulting in things like  body (rather than body) being a selector and incorrectly marked as needing scoping.

@drwpow drwpow merged commit 1f13e40 into main Aug 16, 2021
@drwpow drwpow deleted the fix-body-scoping branch August 16, 2021 23:47
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Unexpected behaviour when applying scoped styling to html and body tags in a layout.astro component
2 participants