Skip to content

fix(tailwind): regex for nonMediaQueryCSS #225

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kabarchonok
Copy link
Contributor

@kabarchonok kabarchonok commented Nov 30, 2024

resolves: #198

So, what do we have.

Several cases affected the styles rendering here, and their influence isn't obvious:

  1. Since the word "container" is present on the page, Tailwind generates a whole class for it, thinking it's being used. This is described in their documentation, so it's worth keeping in mind that this is normal for Tailwind.
  2. The example also involves classes that depend on breakpoints, such as md:p-7.

Let's consider what classes Tailwind generates based on the markup described in the test.

.container {
    width: 100%;
}

@media (min-width: 640px) {
    .container {
        max-width: 640px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 768px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}

@media (min-width: 1536px) {
    .container {
        max-width: 1536px;
    }
}

.hidden {
    display: none;
}

.text-\[\#ccc\] {
    color: rgb(204, 204, 204);
}

@media (min-width: 640px) {
    .sm\:block {
        display: block;
    }
}

Now let's see how the classes for the nonMediaQueryCSS variable were processed before with the regex /@media\s*\(.*\)\s*{\s*\.(.*)\s*{[\s\S]*}\s*}/gmhttps://regex101.com/r/op3l1l/1

In this case, all styles are removed, which is an error, so such an innocent word "container" breaks the appearance.

The solution here is quite simple – correcting the regex to /@media\s*\(.*?\)\s*{[^{}]*({[^{}]*}[^{}a]*)*}/gmhttps://regex101.com/r/i8FZZW/1

P.S. Sorry, I actually had the solution for a long time, I just didn't have time to publish it 🌚

@kabarchonok
Copy link
Contributor Author

This is only part of the problem; in fact, I see difficulties working with Tailwind classes that depend on breakpoints.
If necessary, I can try to configure the rendering of such classes in the head.

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.

Email is not rendered correctly if container text is inside Text component
1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy