-
Notifications
You must be signed in to change notification settings - Fork 256
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
stitches' css is overriding classnames coming from third party lib #1111
Comments
@triptu Facing the same issue. Were you able to come up with a solution? |
For anyone who stumbles here, I was able to find a temporary workaround by ensuring that stitches styles are injected as the first element in head, instead of the last element ( the default behaviour ). This was done by modifying the
to
Note: This is just a quick temporary solution. Like @triptu I'm also open to polishing this approach and submitting a PR if the maintainers want something like this. Otherwise, and if there's enough interest, I can also create a fork ( if the maintainers approve ) |
@Pranav2612000 Thank you for the solution. I used your solution to create a naive fix if anyone needs it running in production.
const fs = require("fs");
const PATH = "./node_modules/@stitches/react/dist/index.mjs";
try {
let content = fs.readFileSync(PATH);
content = String(content);
content = content.replace(
'(e.head||e).appendChild(document.createElement("style"))',
'(e.head||e).insertBefore(document.createElement("style"),(e.head||e).firstChild)'
);
fs.writeFileSync(PATH, content);
} catch (e) {
if (e.code == "ENOENT") console.log("Couldn't find file");
}
Now when your run your Edit: This is working for |
Bug report
I was trying to figure out a way to implement the suggestion here but can't find a way to do it. It seems that stitches always creates a style tag and appends to the document head. If there is a style tag in the head already referencing a 3rd party lib(which gives some classnames), I'm not sure what would be the best way to go forward.
To Reproduce
Also, check the discussion at - #642
Expected behavior
The final output should be yellow
Additional Context
Another important point here is that the stitches part is also coming from a library(but this library is in our control). So the app is using a UI library based on stitches and tailwind for styling, or to override styles in the components coming from the UI library.
Suggestion for Solution
Taking the style tag in
createStitches
config instead of creating a style tag. This would allow the app to have control of the precedence order.I'm open to submitting a PR for this if it makes sense.
The text was updated successfully, but these errors were encountered: