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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dsantolo
Copy link

@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.

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!

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.

1 participant