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

Tailwind CSS issue #4987

Closed
C0ZEN opened this issue Sep 29, 2023 · 44 comments
Closed

Tailwind CSS issue #4987

C0ZEN opened this issue Sep 29, 2023 · 44 comments
Assignees
Labels
Component: Tailwind Tailwind specific issue Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team
Milestone

Comments

@C0ZEN
Copy link

C0ZEN commented Sep 29, 2023

Describe the bug

In v9, to style Prime I only need to add these into a .scss file.

@import 'primereact/resources/themes/lara-light-blue/theme.css';
@import 'primereact/resources/primereact.min.css';

In v10.0.2, this is like the app is set to unstyled: true, since no CSS is loaded, at all!
Though, I'm still able to see that the Prime classes are added into the DOM.

Reproducer

No response

PrimeReact version

10.0.2

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

The styles are loaded.

@C0ZEN C0ZEN added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 29, 2023
@melloware
Copy link
Member

I can't reproduce? https://stackblitz.com/edit/react-bjcylz?file=src%2FApp.js,src%2Findex.js

Can you edit my stackblitz to show the issue?

@melloware melloware added Status: Needs Reproducer Issue needs a runnable reproducer and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 29, 2023
@C0ZEN
Copy link
Author

C0ZEN commented Sep 29, 2023

I can try, though it may not be that easily reproducible since I'm working on a Nx+Vite project.

@C0ZEN
Copy link
Author

C0ZEN commented Sep 29, 2023

I identified that the issue comes from having this line in my styles as well:

@import 'tailwindcss/base';

@melloware
Copy link
Member

ok I think PrimeTek is going to provide guidance on using TailWind with the new unstyled mode.

@melloware
Copy link
Member

Actually instructions here: https://primereact.org/tailwind/

@melloware melloware closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2023
@melloware melloware changed the title The Prime CSS is like unstyled yet a theme css file is imported Tailwind CSS issue Sep 29, 2023
@melloware melloware added Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior and removed Status: Needs Reproducer Issue needs a runnable reproducer labels Sep 29, 2023
@C0ZEN
Copy link
Author

C0ZEN commented Sep 29, 2023

I don't get how come my app is broken just because I'm already using Tailwind.

My point is: tailwind was and should still be working WITH a theme, and the docs actually refer to using tailwind as unstyled.
This is not what I wish 🤔

@melloware melloware reopened this Sep 29, 2023
@melloware
Copy link
Member

OK then provide a reproducer like I did...

@github-actions github-actions bot added Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible and removed Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior labels Sep 29, 2023
@melloware
Copy link
Member

Without a reproducer developers can't really debug.

@melloware melloware added Status: Needs Reproducer Issue needs a runnable reproducer and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 29, 2023
@C0ZEN
Copy link
Author

C0ZEN commented Oct 2, 2023

@melloware here is a reproduction https://codesandbox.io/p/sandbox/prime-10-tailwind-broken-kg22lr

If you delete the import of tailwind/base, the style of Prime is back.

@melloware
Copy link
Member

melloware commented Oct 2, 2023

Yep it is because PrimeReact made a change with this ticket #4959 that has reduced its specificity by adding @layer PrimeReact:

So you can see your TailWind styles are now "winning" over the PrimeReact Theme:
image

image

@melloware melloware added question Issue contains a question about the use of PrimeReact components or the products it supports Component: Theme Issue or pull request is related to Theme and removed Status: Needs Reproducer Issue needs a runnable reproducer labels Oct 2, 2023
@C0ZEN
Copy link
Author

C0ZEN commented Oct 2, 2023

@tugcekucukoglu 👀

@yrios-cdd
Copy link

over the PrimeReact Theme

@melloware I have the same issue. I use primereact in an app that also uses Bootstrap, when upgrading to version 10.0.2 the styles are breaking because Bootstrap styles are "winning" over the PrimeReact Theme. In previous versions of Primereact this did not happen, Primereact styles had priority over bootstrap styles.

@melloware
Copy link
Member

Ok I assigned to PrimeTek to investigate.

@mertsincan mertsincan added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Oct 27, 2023
@mertsincan mertsincan added this to the 10.0.8 milestone Oct 27, 2023
@mertsincan
Copy link
Member

I'll check and get back to you asap. Thanks a lot for your reports!

@melloware melloware added Component: Tailwind Tailwind specific issue and removed question Issue contains a question about the use of PrimeReact components or the products it supports Component: Theme Issue or pull request is related to Theme labels Oct 27, 2023
@gucal
Copy link
Contributor

gucal commented Nov 1, 2023

Hi,

This is a layer problem. Need to implement the layer structure correctly.
Reproducer tools like stackblitz, codesandbox etc. make layers complex. This makes the correct code look wrong.

When used correctly, you will find the stackblitz examples work successfully in your local applications.
You should follow this document for proper use. https://primereact.org/tailwind

This repo works as it should. https://github.com/primefaces/primereact-examples/tree/main/nextjs-styled-tailwind

Thanks for your feedbacks.

@habubey habubey modified the milestones: 10.0.8, 10.0.9 Nov 1, 2023
@rohitdhas
Copy link

rohitdhas commented Nov 6, 2023

So, I tried importing prime-react resource files at the end and it worked! 🎉

Screenshot 2023-11-06 at 2 03 31 PM

@gucal
Copy link
Contributor

gucal commented Nov 10, 2023

Hi,

This is a layer problem. Need to implement the layer structure correctly. Reproducer tools like stackblitz, codesandbox etc. make layers complex. This makes the correct code look wrong.

When used correctly, you will find the stackblitz examples work successfully in your local applications. You should follow this document for proper use. https://primereact.org/tailwind

This repo works as it should. https://github.com/primefaces/primereact-examples/tree/main/nextjs-styled-tailwind

Thanks for your feedbacks.

I don't think you will have any problems with the layer using this method.

If your problem continues to persist, please don't hesitate to inform us.

I am closing this issue now. If you see an error, you can open it again.

Thank you.

@gucal gucal closed this as completed Nov 10, 2023
@gucal gucal self-assigned this Nov 10, 2023
@C0ZEN
Copy link
Author

C0ZEN commented Nov 10, 2023

Hi, I gave it a try and had the same issue again.
I found out why, though; it's because I import the CSS files within my .scss file.
Somehow, it's not the same output.

In your examples, the CSS files are imported within a .css file.

@melloware
Copy link
Member

@C0ZEN you have it all working with Vite and Primereact + Styled Tailwind? Other users are asking and I think I should add an example using Vite here: https://github.com/primefaces/primereact-examples

@melloware
Copy link
Member

Nevermind I figured it out and added a Vite + PrimeReact + Styled + TailwindCSS example: https://github.com/primefaces/primereact-examples/tree/main/vite-styled-tailwind

@melloware melloware added Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Nov 13, 2023
@jerlam06
Copy link

v10 not working on my side. I am using tailwind cli to build tailwind on file change to only extract necessary classnames used in my app. I have tried a few things mentioned above as well as Vite + PrimeReact + Styled + TailwindCSS example. Nothing works for me. Tbh I have never used css layers, and I have no time to dig into it right now. I will stick to v9 until v10 is more stable css-wise, it is a pity because v10 is fixing a few bugs I have.

@melloware
Copy link
Member

@jerlam06 my Vite example above works fine? Can you compare mine to yours and what is broken?

@nikolapalibrk
Copy link

For me it works well when theme is imported in App.js since there I can control the order of imports, and I place the theme at the bottom. But the problem is when I want to implement theme switching ( https://primereact.org/theming/#switchthemes ) where css is loaded by placing link tag in index.html. In that case style from tailwind is loaded later and therefore overrides style from primereact theme.

@melloware
Copy link
Member

@nikolapalibrk that makes total sense. i wonder if there is some way to do that differently to make it load last?

@primperfum
Copy link

I had the same issue and nothing worked for me. Here is my case and solution:
I use Styled Prime components, use tailwind, themes copy pasted in public folder and imported in index.html to easy switch them.

Solution for me was to remove @layer primereact from all the themes CSS files, I dont know why it needs to be there, I know nothing about css layers, but it worked for me and didnt break anything and is good enough for me.

@ArsenicBismuth
Copy link

ArsenicBismuth commented Dec 23, 2023

So, I tried importing prime-react resource files at the end and it worked! 🎉

Thanks a lot for this! Basic theme classes like p-button was overridden by Tailwind, but reordering the CSS (theme.css last) fixed it.

Nevermind, it breaks again somehow?? Man this is so strange. I literally didn't change anything.

@webxzy
Copy link

webxzy commented Dec 30, 2023

没关系,我想通了并添加了一个 Vite + PrimeReact + Styled + TailwindCSS 示例:https://github.com/primefaces/primereact-examples/tree/main/vite-styled-tailwind

good,I'm Ok

@chhmanel
Copy link

So, I tried importing prime-react resource files at the end and it worked! 🎉

Screenshot 2023-11-06 at 2 03 31 PM

This is working for me, thank you so much!

@Vini-Dev-Py
Copy link

Hi guys I'm having trouble getting tailwind css to work with my react prime custom styles, could someone help me? Do you have an example of how to do it?

my more detailed problem is as follows
I have 2 themes a light and a dark where they are alternated by the “changeTheme” function of PrimeReactContext, but a few days ago tailwind was added to the project and at the moment we would like to continue with the styles via scss from primereact, but tailwind overwrote some styles, both of the light and dark theme

I even tried the examples mentioned here, but none of them show the change of themes, I can't do this part...

If I add the import of the light or dark theme in the main.css along with the layers it works, but only with the imported theme, I need a way to switch to both themes.

Translated with DeepL.com (free version)

@melloware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Tailwind Tailwind specific issue Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team
Projects
None yet
Development

No branches or pull requests