-
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
GatsbyImage not working with JavaScript disabled via CSP (uBlock Origin, Noscript addons) #38065
Comments
I use the uBlock Origin extension to disable JavaScript for specific websites in my desktop browser. I can reproduce the issue on https://gatsbyjs.com. |
Hi, thanks for the issue! Unfortunately that is out of our control and I recommend opening an issue on the uBlock repository. <noscript>
<style>
.gatsby-image-wrapper noscript [data-main-image] {
opacity: 1!important
}
.gatsby-image-wrapper [data-placeholder-image] {
opacity: 0!important
}
</style>
</noscript> This way the image is shown inside the other For some reason uBlock wraps this with a <span style="display: inline !important;"><style>.gatsby-image-wrapper noscript [data-main-image]{opacity:1!important}.gatsby-image-wrapper [data-placeholder-image]{opacity:0!important}</style></span> That's not valid HTML and thus not executed. Nothing we can do on our side. |
Thanks for checking it out, @LekoArts! |
Why do you have uBlock Origin replaces Please try removing the unnecessary |
@simevidas you don't seem to understand the explanation. @LekoArts is right. uBlock Origin breaks the page not in one, but in two ways.
This is, most definitely, an issue of uBO. I don't think a web developer should change their selectors because the addon chooses to maul the DOM. Built-in browser methods of shutting down JavaScript work as expected. Issue number one can be fixed easily: changing a selector at https://github.com/gorhill/uBlock/blob/master/src/js/scriptlets/noscript-spoof.js#L33 to only target To fix issue number two, the whole method of replacing DOM needs to be changed. |
@yaroslav uBO replaces As a result, when a user disables JS for a website via uBO, there will be no In order to be compatible with such users, a website must not rely on the existence of |
The standard way to handle clients with no JavaScript available or disable exists and is very thoroughly documented. https://html.spec.whatwg.org/multipage/scripting.html#the-noscript-element Are you suggesting to replace an actual standard with the support for a very specific browser add-on where the JavaScript blocking DOM modifications are not even documented? |
I’m suggesting to remove the unnecessary |
The gatsby/packages/gatsby-plugin-image/src/gatsby-ssr.tsx Lines 103 to 108 in 22394b9
If we'd change the the selector, all images would be visible directly, without a blur-up effect. Thus the |
test: .gatsby-image-wrapper :is(noscript, span[style="display: inline !important;"]) [data-main-image]{opacity:1!important}
.gatsby-image-wrapper [data-placeholder-image]{opacity:0!important} of course this cuts off support of old browsers: https://caniuse.com/css-matches-pseudo The worst is using Rather, the project is not so crazy that it would add to the html code by itself The idea of NoScript detection I don't have - as they do not use the identical method as uBo. |
@LekoArts If we remove <noscript>
<style>
.gatsby-image-wrapper [data-main-image] {
opacity: 1!important
}
.gatsby-image-wrapper [data-placeholder-image] {
opacity: 0!important
}
</style>
</noscript> There are two scenarios:
To sum up, Please try removing |
Preliminary Checks
Description
It seems that while GatsbyImage is designed to have the
<noscript>
tag support and work with both JavaScript enabled or disabled, this is not always the case.Many prosumers seem to use uBlock Origin (gorhill/uBlock#308) or NoScript for blocking JavaScript for a single specific website. They seem to work by setting policies for a specific page that completely block JavaScript. However, with that blocking enabled, GatsbyImage images stop showing.
Reproduction Link
gatsbyjs.com
Steps to Reproduce
It works:
about:config
and setjavascript.enabled
tofalse
.It does not, however:
</>
looking icon, reload the page).The issue is reproduceable for me on both production Gatsby websites (Cloud and not-cloud) as well as on local
gatsby serve
builds.Expected Result
Images still show up using what is in
<noscript>
tag.Actual Result
Despite
<noscript>
getting used by the browser, the image in that tag seems to have theopacity
or0
, so all I get is an empty placeholder.Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: