Skip to content
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

[Bug]: 奇怪的 bug,某些页面某些jit 类名转义失败 #556

Open
YeYbfwad opened this issue Jan 17, 2025 · 10 comments
Open

[Bug]: 奇怪的 bug,某些页面某些jit 类名转义失败 #556

YeYbfwad opened this issue Jan 17, 2025 · 10 comments
Assignees
Labels
bug Something isn't working need more info

Comments

@YeYbfwad
Copy link

weapp-tailwindcss 版本

3.7.0

框架 & 小程序平台

taro react 编译到微信小程序

最小复现bug的代码仓库链接

No response

复现bug的步骤

遇到一个很奇怪的问题,某些页面下,jit 某些css会编译失败(比如 py 的 jit css编译错误,这个页面所有的 py-[xxx] jit css 都会编译错误),会编译成下面的样子,请问有什么方法可以排查是什么原因导致的,最小化仓库无法复现
Image

taro版本:4.0.9
tailwindcss版本: 3.4.17

预期是什么?

正常编译

实际发生了什么?

类名编译错误

运行环境

其他附加信息

No response

@YeYbfwad YeYbfwad added the bug Something isn't working label Jan 17, 2025
@sonofmagic
Copy link
Owner

在 taro 中,由于 tailwindcss class 是写在 js / jsx 里面的,这时候转化流程是,weapp-tailwindcss 会和 tailwindcss 进行通信,然后从它上下文里面,去取出 classname 进行转义,所以只有被 tailwindcss 提取到的 token 才会被转义。

所以需要保证你写的所有的 tailwindcss class ,都在 tailwind.config.js 的 content 选项包裹的范围内。

@YeYbfwad
Copy link
Author

@sonofmagic content 已经确保是包围了的,它现在主要是只是某些 jit 变量突然解析不了,比如元素同时具有 px-[32px],py-[32px]这样的 jit css,然后 px-[32px]是成功转义的,但是 py-[32px]无法转义,如上面的图一样,就变成 py- 32px 这样,但是这个 bug 我暂时不知道怎么复现

@sonofmagic
Copy link
Owner

了解,我先在我的 demo 里面复现一下这个问题,另外我想知道你的 taro 是 webpack5 还是 vite

@YeYbfwad
Copy link
Author

@sonofmagic webpack5,比较奇怪的是,a 页面是没问题的,b 页面有问题(普通分包),但两个页面都会有某些 jit 变量失效,确保不是动态变量,写死的

@sonofmagic
Copy link
Owner

不知道能不能在这个 https://github.com/sonofmagic/weapp-tailwindcss/tree/main/demo/taro-app 复现
我试了一下,在主包里面这样写没问题,怀疑可能是分包引发的,不知道有什么稳定复现的条件,您能fork在这个 demo 里面提交一下,或者你指导我一下如何进行复现吗?

@YeYbfwad
Copy link
Author

@sonofmagic 目前在这个项目暂时复现不出来,复现出来后我会在这 issue再次回复

@YeYbfwad
Copy link
Author

@sonofmagic 这个问题我貌似跑一次weapp-tw patch 就没问题了,那是不是每次新增页码都得跑一次weapp-tw patch,或者运行项目的时候,前面先运行一次weapp-tw patch

@sonofmagic
Copy link
Owner

不是的,这个命令只需要放在你的 postinstall 这里执行就行,
weapp-tw patch 本质上这个命令是为了打通 weapp-tailwindcss 和 tailwindcss 的通信管道。
tailwindcss 只有在每次安装包的时候才会去更新,那这个命令也只需要在安装的时候更新就行。

详见: https://tw.icebreaker.top/docs/quick-start/this-plugin

@YeYbfwad
Copy link
Author

@sonofmagic 我之前也是按照文档去更新的,但目前解决方法是我手动跑一次weapp-tw patch就没问题了,但我不知道为什么这样可以解决到我的问题

@sonofmagic
Copy link
Owner

@YeYbfwad 我也感觉非常奇怪,因为我这个 weapp-tw patch 是跟着 tailwindcss 走的,tailwindcss 不变,没有重新安装的情况下, weapp-tw patch 是不需要执行的。
难道是你的 tailwindcss 这个包下面的内容一直在变化?搞不大懂,最好有个复现的用例,或者方向啥的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need more info
Projects
None yet
Development

No branches or pull requests

2 participants