franken-ui / ui

Franken UI is an HTML-first, open-source library of UI components that works as a standalone or as a Tailwind CSS plugin. It is compatible with UIkit 3. The design is influenced by shadcn/ui.
https://franken-ui.dev
MIT License
1.78k stars 26 forks source link

Breakpoints are rendered before normal styles when bundled using tailwind #16

Closed osiloke closed 3 months ago

osiloke commented 3 months ago

This only happens when bundled with tailwind cli. The CDN static css works as expected.

This is due to the placement of width media query directives before the general css directives in the released npm package.

Screenshot 2024-08-01 at 11 02 14 AM
osiloke commented 3 months ago

Moving the media assignment code below the base css assignments solves this issue. Please let me know if i can submit a PR.

Screenshot 2024-08-01 at 6 03 45 PM
sveltecult commented 3 months ago

Hello @osiloke

Thank you for reporting this issue. You are absolutely right that it only occurs when bundled with Tailwind CLI, whereas the CDN static CSS works as expected.

Have you considered installing PostCSS alongside Tailwind CLI? Alternatively, you could use npm create vite@latest, which comes with built-in PostCSS support. This would allow you to simply run npx franken-ui init -p and have everything set up for you.

Regarding your suggestion to move the media assignment code below the base CSS assignments, I appreciate your willingness to submit a PR. However, I believe I've explored this solution before and found that it can still cause issues due to improper sorting. I know, it's weird. I expected browser to sort rules by themselves but I was wrong. If I remember correctly, it's the Width component that's malfunctioning.

During the early releases I discussed this in the docs. But, it already been updated multiple times and eventually got removed and replaced by the CLI method.

The simplest solution would be to utilize PostCSS, which is already included in the package. This would eliminate the need for additional installations and also remove duplicated rules caused by hooks.

module.exports = {
    plugins: [
        require('tailwindcss'),
        require('franken-ui/postcss/sort-media-queries')({
            sort: 'mobile-first'
        }),
        require('franken-ui/postcss/combine-duplicated-selectors')({
            removeDuplicatedProperties: true
        })
    ]
};
osiloke commented 3 months ago

Ok that makes sense. I'm using a Go/HTMX setup so vite is not an option.

However, the postcss fix works. Thank you for the suggestion.