-
DescriptionI am experiencing an error that I suspect may be related to my use of ThemeProvider in @emotion/react. My site works in development but in the production build, all images queried with childImageSharp remain in the "blur up" mode (links to the images are data: links instead of links to the static files); and any elements that contain event handlers no longer work (theme toggle, dropdown menus). The browser console logs the following errors:
There are also a few errors that state: This is not my day job, and this is my first Gatsby project, so forgive me if there is a painfully obvious solution. I've searched around and while I did find some issues in which people described similar problems loading images (#25783), nothing was quite on point or provided me with a working solution. Steps to reproduceOn the production build, the image loads and the toggle button works until I add ThemeProvider from the @emotion/react package. Then it only works in development, but not production. Here is a minimal reproduction: https://github.com/bueide/gatsby-bug-reproduction. The reproduction uses the gatsby hello world starter with the following added dependencies:
Expected resultThe JS should still work on the production build (event handlers, images loading etc.). Actual resultThe site builds without throwing any errors, but the images do not load beyond the blur up placeholder image, and no event handlers work. The browser console logs the errors described above. EnvironmentSystem: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, I solved the problem. The issue was not with ThemeProvider; rather, it was with me wanting to pull a user's previous theme selection from localStorage. I thought I had solved that adding the The added code on line 12 of the following screenshot fixed the problem (disregard the change inside the useEffect hook, that is irrelevant and a relic of me fiddling around). Sharing in case anybody else is dealing with the same issue and comes across this post. |
Beta Was this translation helpful? Give feedback.
Ok, I solved the problem. The issue was not with ThemeProvider; rather, it was with me wanting to pull a user's previous theme selection from localStorage. I thought I had solved that adding the
typeof window !== 'undefined' && window.localStorage
code, but what I did not realize was that the code, as I had written it, was returning a null value for the stored theme on the initial rendering of the site after it was built.The added code on line 12 of the following screenshot fixed the problem (disregard the change inside the useEffect hook, that is irrelevant and a relic of me fiddling around). Sharing in case anybody else is dealing with the same issue and comes across this post.