-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby-plugin-image class styles break user created styles & CSS frameworks like Tailwind CSS #34457
Comments
I'm experiencing this issue as well. I just wanted to add that the behavior of the issue is different for development and production. Successful workarounds for |
Hi! This is not something we'll fix as the styles for the image component are there for a reason (best performance, best lighthouse scores) and thus we don't want people to easily overwrite them. You should create a wrapper to do your layouting or directly use the |
I don't understand what you're saying. Can you help me understand?
This won't work since the wrapper always has
In this case How would you suggest fixing this? It isn't clear to me. Also it's confusing because it works on local dev instance but fails on prod builds. The behavior seems strange to me. |
I fixed by adding a wrapper class with virtually the same properties which hid the gatsby image. |
I understand the motivation to make these styles hard to overwrite, but the ideal behavior is definitely to have the same results while running |
I personally have an issue where gatsby images basically live their own life in prod builds but work absolutely fine in dev. Switching to img tag helps, but it's not optimal... |
This is such an annoying "feature". Everything looks good in dev, then you merge the PR and CI builds it to test environment, bam, everything looks like crap. How can the |
Bump, to have such differences between dev & prod environments is very annoying and dangerous |
This "We know better than you" mentality is what drove me of create-react-app, but if it's the same in the gatsby community, we have no other choice than to chose another framework. |
This is quite frustrating. There should be exactly the same result between dev and build. Issues are one thing but an attitude of not willing to fix really helps drive me, and I'm sure others, away from Gatsby. Please, hopefully reconsider. |
Some tailwind classes must be marked with important to override gatsby-image-wrapper Issue: gatsbyjs/gatsby#34457
Preliminary Checks
Description
The current implementation of
gatsby-plugin-image
injects it's CSS classes in a<style>
element that is placed last in the DOM tree, after user created styles loaded viagatsby-browser.js
. Making it impossible to override any of its default styles with a normal class unless using a higher specificity selector (ID/inline). Notably, this breaks class driven CSS frameworks like TailwindCSS unless prefixing utility classes with!important
.For example, assuming the following simple code sample: (css loaded via
gatsby-browser.js
)When building the project, the output image container has the styles of both TailwindCSS's
![Screenshot_2022 01 12_03 15 AM](https://user-images.githubusercontent.com/7468219/149098842-2613ea37-3575-42f2-8599-bdc3975d27a8.png)
absolute
class, and a custom user created class overriden bygatsby-plugin-image
's styles because they are placed lower in the DOM.Evidence of the problem is made clear when browsing the output rendered HTML by Gatsby's build in the Chrome Inspector:
A solution here would be ensuring that the gatsby-plugin-image CSS is always loaded FIRST in the DOM tree, allowing user created classes of equal specificity to win against it.
It appears other people have faced this issue as well. #33960 stumbled upon this issue, and there is a Stack Overflow thread of people facing the issue and looking for work arounds like
!important
to all tailwind classes or using inline styles to beat the styles by gatsby-plugin-image:https://stackoverflow.com/questions/66763196/gatsby-image-plugin-staticimage-cannot-override-the-default-wrapper-style-gats
Reproduction Link
https://github.com/sgarcia-dev/my-first-gatsby-siteww
Steps to Reproduce
Using linked project:
gatsby-plugin-image
tosrc/pages/index.js:12
...
Expected Result
User created styles or CSS framework classes should not be overriden by
gatsby-image-plugin
by defaultActual Result
User created styles or CSS framework classes are being overriden by
gatsby-image-plugin
by default, forcing users to find weird workarounds for this issue.Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: