-
-
Notifications
You must be signed in to change notification settings - Fork 80
Class getting stripped out unnecessarily #218
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
Comments
Hey @brandonmcconnell! 👋 This is because It's similar to how |
@dcastil Thanks for clarifying that! I believe—though I could be wrong—if you have both a It would be great if tailwind-merge offered a setting to allow utilities like these and those you mentioned to not be considered conflicts and to allow TailwindCSS to handle their overrides naturally. |
Also, if they're considered conflicts and I set |
If you put But e.g. think of a component that defines a line-height with But you can change this behavior by the way! You can remove this conflict from the config (this one). const twMerge = extendTailwindMerge({ /* your config */ }, config => {
delete config.conflictingClassGroups['font-size']
return config
}) |
@dcastil Thanks! |
@brandonmcconnell I'm closing this issue as resolved. Let me know if your issue persists. 😊 |
@dcastil Just wanted to confirm— using |
Yes! |
@dcastil Awesome, thanks! |
Mentioned this issue in #226 (reply in thread). |
Simple TypeScript transformer which spits something out on the import clsx, { type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
const missingWords = (before: string, after: string) => {
const afterArr = after.split(" ");
return before
.split(" ")
.filter((w) => !afterArr.includes(w))
.join(" ");
};
const twM = (...inputs: ClassValue[]) => {
const joinedClasses = clsx(...inputs);
const mergedClasses = twMerge(joinedClasses);
if (
process.env.NODE_ENV === "development" &&
joinedClasses !== mergedClasses
) {
console.trace(
`twM: "${joinedClasses}" lost "${missingWords(
joinedClasses,
mergedClasses
)}"`
);
}
return mergedClasses;
};
export default twM; If you want a shorter stack trace, you can use this approach, but you won't be able to click through to the source file (or at least I haven't been able to figure out how): const getCaller = () => {
const err = Error("");
const callerLine = err?.stack?.split("\n")[4];
return callerLine?.trim().replace(/^at /, "from ");
}; Replace the console.log(
`twM: "${joinedClasses}" lost "${missingWords(
joinedClasses,
mergedClasses
)}"
${getCaller() || ""}`
);
|
I have this, roughly—
I can't figure out why
leading-tight
is getting removed.Here is my implementation of
cls
:Thanks for all the help, as always 🙏🏼
The text was updated successfully, but these errors were encountered: