tailwindcss-capsize icon indicating copy to clipboard operation
tailwindcss-capsize copied to clipboard

Breaking with Tailwind 4.x

Open LilaRest opened this issue 10 months ago • 9 comments

Hey!

We just upgraded to Tailwind 4.x and our builds were failing with the following error: TypeError: undefined is not a function

After disabling the tailwindcss-capsize, the issue is gone.

Any idea about what in the plugin could be leading to that error?

LilaRest avatar Jan 30 '25 16:01 LilaRest

I wonder if v4 changed something about the internal corePlugins which this plugin tries to override... 🤔

stormwarning avatar Jan 30 '25 18:01 stormwarning

@LilaRest, having forward/backward compatibility for Tailwind plugins would be a huge luck this days. Internal architecture changes of config and plugin systems of Tailwind v4 vs v3 are simply too deep.

andriytyurnikov avatar Jan 30 '25 18:01 andriytyurnikov

Well shit: https://tailwindcss.com/docs/upgrade-guide#disabling-core-plugins

In v3 there was a corePlugins option you could use to completely disable certain utilities in the framework. This is no longer supported in v4.

I think it might be possible to have it work without disabling corePlugins but it might mean the built CSS isn't as "clean" — for example, there'd be a text-lg class from Tailwind with the font-size property, and a text-lg class from this plugin which just sets the custom property used in the text-box-trim calculation

stormwarning avatar Jan 30 '25 18:01 stormwarning

Hey @andriytyurnikov and @stormwarning, thanks for your input here!

I've identified that the above error was due to the plugin function no longer receiving the e() function as a parameter. I managed to temporarily fix it by explicitly defining e() in the plugin file.

function e(className) {
    return className.replace(/\\,/g, '\\2c ');
}

I've found the source code of the function here and removed the usage of postcss-selector-parser because it was raising some errors. I'm not sure this implementation will work for all the edge cases, but for now it works.

Happy to get your thoughts on that!

LilaRest avatar Jan 30 '25 23:01 LilaRest

Luckily for me - my personal capsizing plugin has no users, so I am just abandoning it. I applaud to your grit though - tailwind plugin users are caught between a rock and a hard place. I suspect your fix will be needed by many. Thanks for sharing, @LilaRest !

andriytyurnikov avatar Jan 30 '25 23:01 andriytyurnikov

I've seen that you pushed some updates yesterday @stormwarning, did this included the patch to this bug? Or should I maintain a version of this plugin in our monorepo as it won't be updated?

LilaRest avatar Jan 31 '25 08:01 LilaRest

Not yet, just updating some devDependencies while I dig into the issue. I'll do a proper release when I get a working version; I had some trouble even getting tests to run yesterday 😓

stormwarning avatar Jan 31 '25 10:01 stormwarning

@LilaRest are you using the new CSS config, or a path to a JS config?

stormwarning avatar Feb 20 '25 16:02 stormwarning

@stormwarning A path to a TS config

LilaRest avatar Feb 20 '25 19:02 LilaRest