Skip to content

fix: prevent Svelte files from breaking when there are duplicate classes #359

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

Merged

Conversation

dsantolo
Copy link
Contributor

@dsantolo dsantolo commented Apr 27, 2025

As of v0.6.11, Svelte files still break after saving a file that contains duplicate classes in template strings (related to #303).

This seems to be because of a bug where there are certain times transformSvelte results in calls to sortClasses that don't pass removeDuplicates at all, but sortClasses defaults it to true, resulting in the plugin attempting to remove duplicates even though this is not supported yet in Svelte.

Now, we pass removeDuplicates in all cases. In the case of string literals, this results in the classes being sorted with the duplicates remaining (without breaking your project). Getting the functionality of removing duplicates removed in string literals requires more work.

However, it seems that removing duplicates in the normal "text" (non-literal) case works totally fine in Svelte, so I decided to enable removing duplicates in that case. Added some new tests with duplicates in the 3 different cases that all pass.

Before

Expected: <div class={'flex flex underline'}></div>
Received: <div class={'flex underline'}></d}></div>

Thanks to @onsclom for helping on this!

@thecrypticace thecrypticace self-assigned this May 23, 2025
@thecrypticace thecrypticace merged commit cd8832b into tailwindlabs:main May 30, 2025
1 check passed
@thecrypticace
Copy link
Contributor

I can clearly see where I thought I'd done this already but… didn't 🤦‍♂️

Thanks for the fix! It should be available via the insiders build in a few minutes:

npm install prettier-plugin-tailwindcss@insiders

I'll likely get a tagged release out next week.

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.

2 participants