-
Notifications
You must be signed in to change notification settings - Fork 49
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
Randomly generated classNames bust cache on hosting services like Netlify (and maybe browsers too...?) #154
Comments
Hi @f-kottek, that's a strange behavior. As in
Best, Tim. |
Hey @timhagn, it's a private repo for a company-website, so I can't share the whole thing unfortunately.
The instance of BgImage is the only one in the component and on the page. The class name is arbitrary, as in the first example and only for demo purposes, The page works fine, the image is there and in the background etc. -> all good.
some info from our package.json that might help/be important:
Edit: not using this plugin anymore |
Hi @f-kottek, now I got you. It is a bug & I even already know where & why it happens (see lib/StyleUtils.js.
Will look into it further as soon as I find the time (just closing shop for the day and am in Austria ; ). Grüße aus Wien : )! Best, Tim. EDIT: add correct |
Hey @timhagn, it works, thanks! |
I believe my issue might be related to this. |
The same here. I got a Prop
to solve the problem. |
This technically doesn't solve your problem. You just hide it. AT the end of the day, you have to build the project and do SSR. The same problem will still be hit when doing rehydration on the client-side, and it has a major impact on performance even though the warning message is hidden. |
I've recently noticed an issue with several of my Gatsby sites that use this plugin in combination with gbimage-bridge and gatsby-plugin-image. Since upgrading to React 18, production builds display console errors indicating a Minified React error. The errors have to do with hydration and the UI rendered being different than what's on the server. I chased this down a bit and think it's related to this issue in that the component is automatically generating a random hash for classnames and also generating a new one on each refresh of the browser. So you don't actually need to rebuild the project and deploy it, if you refresh your browser you will see different classnames. For example, here's an abbreviated version of what the wrapper tag looked like when I first visited the page.
And then after I refreshed, here's an updated version of the tag.
I reverted back to React 17 and didn't see these hydration errors in production builds, so it's only after upgrading to React 18 that they seem to appear and there's no errors displayed when running in development mode. I also tried the same thing in React 17 and the classnames do change on every page refresh. I've created a repo to easily reproduce the problem.
Once it's up and running, open a browser at http://localhost:9000 and view the console errors. |
Any progress on this one? |
I can confirm problems relating to this issue too. With React 18, I get the After reverting back to React 17, I see only the |
Summary
When you are using this plugin with a service like Netlify, you end up generating a lot more files to upload at each build, than you need to. Pages that don't change at all, but include
<BgImage />
-components will get a new hashed className on each rebuild. This will invalidate Netlifys cache and the file will be uploaded as a new one. This will on some scale be detrimental to build times and because of the cache-busting might even lead to worse page speed scores.(And aren't we all after the perfect 100/100/100 with Gatsby? 🥇)
Basic example
This will be rendered by the component:
on the next rebuild, the hash-value will change -> problem
I just added the "arbitrary-class" for demonstration purposes.
Motivation
Possible Solution
I propose a prop/flag that lets you opt out of hashed classes. I know the reasons why the hash-value is there, but it currently generates some unwanted and detrimental behaviors. I guess if you're using this flag, you can get away with setting individual classNames for every instance of the component, but that's something that you need to be aware of. Maybe therefore name the prop something like "dangerouslyOptOutOfHashes" to remind yourself of setting a distinct className? 🤔
The text was updated successfully, but these errors were encountered: