-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Tailwind: NextJs production build removes styles #5187
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I managed to resolve it by adding this code to the layout.tsx file: <head>
<script
dangerouslySetInnerHTML={{
__html: `
const style = document.createElement('style')
style.innerHTML = '@layer tailwind-base, primereact, tailwind-utilities;'
style.setAttribute('type', 'text/css')
document.querySelector('head').prepend(style)
`,
}}
/>
</head> It doesn't seem to be the best way to solve it, but it was the only one that worked. Source: [PrimeReact] How to fix styles NextJS + Tailwind (@SoyDiego) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I also saw this issue, but it is not always reproducible. From my research, then the problem is in the way Next.js bundling CSS layers in production. There is a long thread that originates from 2020 on this matter, and seems like it won't be fixed anytime soon. |
I tried the solutions above , but it seems that if you're using a theme from primereact, these solutions won't work. However, the following worked for me : following the instructions from primereact, in your
the key is to include your theme's css file as the primereact layer in your css file-- this has worked as a workaround for me when deploying to vercel. the order is important here, so it's important to import the css after declaring the tailwind-base, primereact, tailwind-utilities layer. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I just updated this example for Next 14 and its working in Dev and Prod mode and showing the styles fine: https://github.com/primefaces/primereact-examples/tree/main/nextjs-styled-tailwind |
In nextjs app router still not showing when prod mode, where nextjs app router example? |
@YadBro subscribe to this issue: primefaces/primereact-examples#19 |
I think this issue is theme, previously i used "primereact/resources/themes/saga-green/theme.css", and i change to "primereact/resources/themes/lara-light-green/theme.css" and then build it work, but not full loaded too. like hover text-color is not loaded but in dev is loaded |
Thank you, this works for me. Would love to find a more solid solution. I've been through most related Gitlab\Stack issues and have tried several potential fixes but only this seems to work for me. |
I'm glad my workaround helped you |
@BrettSGA are you saying this example did NOT work for you: https://github.com/primefaces/primereact-examples/tree/main/nextjs-styled-tailwind That one was working for me last I tested it in both DEV and PRD mode. |
@melloware dangerously setting the inner HTML does work, but I would really like to avoid that in production. |
@codingHanna you see my example above works if you check it out and run |
Describe the bug
When running a dev build, the default Primereact Tailwind style seems fine. However when doing a prod build, it's removed.
Dev build:
Prod build:
Reproducer
https://codesandbox.io/p/sandbox/dazzling-paper-7mmcnz
PrimeReact version
10.0.7
React version
18.x
Language
TypeScript
Build / Runtime
Next.js
Browser(s)
No response
Steps to reproduce the behavior
No response
Expected behavior
Default Tailwind style should appear when doing a production build.
The text was updated successfully, but these errors were encountered: