-
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
Server-side-rendered styles are missing and/or incorrect #17676
Comments
So to get on the same page here: This reproduces the issue you are seeing on your page? |
Hey @LekoArts, no. I think my comment confused you. I can't share the actual code repository where the issue is occurring. Here's a link to the deployed web-app where we see the issues happening. This So I'm trying to understand what else could have gone wrong because the setup itself seems to be working fine. If it's going to be helpful I can share some snippets of the source code? Update I had a gut feeling that the I'm testing the app built by If that's the case, then we can narrow down the issue to styles getting messed up by the service workers and the offline plugin? The plugin is installed like:
Update 2 Ok, my previous speculation about the I'm still able to reproduce the issue and the only fix is to clear the locally stored site data through Developer Tools tab. Another quite interesting finding is that opening links in a new tab ( Still researching on a potential cause... Update 3 I'm uploading a screenshot where the issue is clearly visible. This is quite odd and possible the reason:
However, these styles are not present in the CSS inspector at all 🤔 |
Sorry to hear that you still have problems :/ However, we can only really investigate your issue with a reproduction. If you can reproduce your issue with the starter you linked you maybe also get behind what the issue could be. |
I am having this same issue, I believe, with my site after upgrading to Gatsby 2. I since rolled back to Gatsby 1 but wanted to get back into checking this. Adding my 👍 so I can track any resolutions or contribute any help/notes. I, too, thought it might be the offline plugin, but that turned out to be a false lead. |
Here's the project repository for our docs site: https://github.com/enactjs/docs/tree/feature/v2-migration |
Noting that #10370 appears to be a similar issue. |
#8560 there are many related issues but this is one of the most consistently mentioned ones. You can “solve” the problem by wrapping the components whose CSS is not rendering correctly on first page load, as mentioned in the linked issue, but obviously it’s not ideal |
Sounds very much like #14601. I'm experiencing this again, this time non-deterministically and without a clear workaround. I believe this is currently a CRITICAL (not major) bug with Gatsby, and shouldn't be overlooked as it did before. This is likely not a bug with any particular plugin, but rather a design problem that was caused by changes to React's hydration introduced in version 16 (see #14601 for more on that). @DSchau your thoughts? |
Actually, looks like there is a much older ticket for this issue - #8560. |
Hey @eyalroth, thank you for sharing these threads. I re-read the comments there, but still, it seems like there's neither a clear understanding nor a solution. We're still experiencing this issue and my thoughts about it are currently scoped to:
-- There's one more thing I found out. Might be a false signal, but worth mentioning. Here's the explanation: As per my understanding, Material UI's Core package uses the Styles package internally. So we dropped
However, I reviewed the example integration in this repository and noticed that it still uses Styles instead of core. So we rolled back and imported styles-related modules from the Styles package.
Strangely it seems like the issue is happening less often now. When I get a chance this week, I'll replace all Styles-related imports like that and report back. Again this might be non-sense, but might be helpful input. |
@SMerdzhanov I believe this is not related to CSS per-se, but rather to any change in HTML attributes ( Do you happen do have anything in Edit: This could actually be due to any one of the plugins you're using. For instance, |
Hey @eyalroth, I just reviewed your comment and it makes a lot of sense! At some point, I too thought that it's just the However, the bug still occurred. Maybe it's related, but it's a symptom rather than the cause. I'm eager to resolve this and help in any way I can. I'm trying to fight it too! So please let me know if you want me to test, report or assist! 👍 For reference here are my
and
and finally
|
@SMerdzhanov I really don't know why it still persists without the offline plugin. Honestly, I'm pretty new with Gatsby / React / JavsScript. You could try to isolate the bug by removing plugins and code step by step until the bug disappears. This is what I did with my site until I found the minimum code required to reproduce the problem. |
@SMerdzhanov One more thing before you start deleting code to detect the source of the bug. Can you make sure to disable the offline plugin in the following way?
This is what I did when I wanted to make sure that the offline plugin is the culprit. Perhaps you didn't make one of these steps. Also, I didn't use the "uninstall" plugin for the service worker. |
@eyalroth just followed your instructions like
Testing for like 10 min did not trigger the glitch which is promising, but I wouldn't count on it, because it's quite tricky to reproduce anyway. I found quite surprising that opening a link in a new tab through Let's assume that's it, meaning that -- I can probably make an experiment and push this live with disabled offline mode. To achieve that I'll have to use the "uninstall" plugin we both mentioned. There it will be exposed to many more users and I can verify it with more certainty. I might be able to do that tomorrow and update this thread. |
As someone mentioned, it's not restricted to |
Guys, can you try applying the workaround I just posted in #8560 (replacing the hydrate method with render)? |
Also, I believe this to be exactly the same issue as #8237. There's a comment there suggesting that the "replace hydrate" workaround should solve the issue. |
Hey @eyalroth, I see issue #17914 that you created and can't agree more. I will follow it. I'm just pushing live the replaced hydration workaround you suggested. Note that I haven't turned off
I did I still can't find a good way to reproduce it every time so we can debug it properly. Anyway, I'll try to get more people testing it and will report when there's an update. |
The replacement of the hydrate function worked for me. Fortunately, that uncovered a bug that I had in my code that was causing the deployed and re-rendered version of the site to actually be different from what the server side rendered code was. So, I think if I can address that bug I might can fix the rehydrate issue I was seeing. |
Hey @webOS101, how did you replicate and verify the fix so I can try it out too? Do you think that this uncovered bug might be affecting someone else too? If so, can you please share it so we all look into this possibility? |
I think the bug is pretty specific to some shenanigans I'm pulling to make Gatsby run in directories other than the one the deploy command specifies with |
Let's keep discussing in the "Meta" issue as writing across multiple different issues is just really cumbersome. #17914 |
@SMerdzhanov I linked a repository to reproduce the problem in both #8560 and #17914. My process for reproducing the problem was, as I mentioned earlier, cutting off parts of my site (perhaps the I did that in conjunction with another repository cloned from the default gatsby starter, which I modified to eventually contain all (and only) the parts that caused the problem in my site. |
Hey hey, just wanted to post for clarity/shared knowledge? I'm currently building a Gatsby + MUI site with dynamic client-side routes and am experiencing some issues when my page gets rehydrated. Initial load to I tried the solution mentioned above by @eyalroth and replaced my hydrate function with a rerender and that seems to have fixed my problems but I agree that that might be more of a workaround than a solution. I just wanted to post here since I found this thread in my search for an answer. Best of luck! |
not sure why this is closed. I had to implement the same workaround
|
@SMerdzhanov Thx!! I banged my head for hours on this. |
@monsieurBoutte @anthonytison This issue is tracked in #17914. |
Installing this Gatsby plugin resolved the issue for me: https://www.gatsbyjs.com/plugins/gatsby-plugin-material-ui/ |
This was hurting my head for hours. I can't believe it, it was because I used class={} instead of className={} for one of my components. Thanks! |
Description
I've built multiple sites/apps with Gatsby already, but that's the first time I encounter such an issue.
I'm working on an app based on Gatsby and Material UI.
GitHub issues reporting similar, but not the same behavior that I reviewed and tested #9911, #12360, #5100, #3741.
GIF/recording of the issue https://monosnap.com/file/gQ7jH0YQ4O39LpHhL8DOL40eufnbbY
Sometimes, on initial page load (server-side-rendered per my understanding) the styles get totally messed up. This does not happen on subsequent (client-side) rendered pages, but only on the initial page load. Unfortunately, it occurs randomly and not on every build.
Setup
The setup of Gatsby and Material UI is based on MUI's official Gatsby example.
In short,
gatsby-plugin-material-ui
and changes togatsby-browser.js
andgatsby-ssr.js
This very same setup, as described in the GH project itself, works perfectly fine on other projects. Therefore, I speculate there's something that we're missing.
styled-components
or any similarCSS-in-JS
library and such doesn't exist inpackage.json
.css
files we have are placed at the top ofgatsby-browser.js
like thisgatsby-plugin-material-ui
's option forinjectFirst
as described here, but without any success.gatsby-plugin-offline
Steps to reproduce
Unfortunately, I can't grant access to the project's repository. I have the very same project setup as GH repository that I'm sharing for reference.
gatsby develop
works perfectly fine.gatsby build
passes just fine too. No warnings or errors.gatsby serve
serves the already built files. However, styles get messed up as described in this issue.Expected result
It's expected to load any styles properly on both initial and subsequent renders.
Actual result
The styles on initial-render get messed up and/or are corrupted. Please check the video recording at the top of the issue.
Environment
Thank you for spending the time to look into this!
The text was updated successfully, but these errors were encountered: