-
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
Flicker of Unstyled Content #5667
Comments
What happens when you use that plugin? If you disable JavaScript and reload the page, do the styles download? If it's running Material UI's server side rendering that should fix the issue you're seeing, I think. The plugin you linked looks to be using Gatsby's |
Maybe I'm a bit confused about how this plugin works. I don't really use a 'theme' to power my Material UI components-- I'm grabbing them from the examples and using them that way, and defining my own colours using Styled Components. I defined a theme as per their spec and the problem persists. If it helps, I basically built my site using this article as guidance. Can you tell me a bit more about server side rendering? I'm not too familiar with it when it comes to React and MUI. That might be part of the solution I'm looking for. I also tried out the plugin for styled components but that doesn't seem to work for me either-- it also conflicts with the MUI plugin. |
I have this issue on a super lightweight page in regards to fonts. It takes a second for the fonts to be applied even though the page is just literally 5 images and small amounts of text. How can i avoid this? It looks pretty bad. I'm using the google font node module for the typeface |
I have the exact same issue, super small page and terrible FOUC, only when deployed to Netlify, no problems on local dev environment. Also using Material UI v1 components. |
I think gatsby-plugin-material-ui needs an update. |
So, I work with @mbuttler and spent some time looking into the issue and got everything working. There were actually a few issues for us that lead to the problem.
What we ended up doing is writing a custom gatsby-ssr.js that applied the styled-components plugin wrapper and the code from the material-ui gatsby example. Also using the (pageContext)[https://github.com/mui-org/material-ui/blob/master/examples/gatsby/src/getPageContext.js] and (withRoot)[https://github.com/mui-org/material-ui/blob/master/examples/gatsby/src/withRoot.js] files from the example. This helps ensure that the SSR themes that are applied in the gatsby-ssr file are same ones that are applied on the client-side rendering so you don't get a flicker of changed style when the client-side js is loaded. Our resulting gatsby-ssr.js file looks like this:
|
Thank you very much @pdhodgkinson for the great insights and your results. I have still some problems though and I am not sure yet how to solve them. Maybe you can spend some minutes and help me? It is about the following page: natterstefan/react-trello-multiboard-page#1. I am trying to add pages with *.md files. According to the docs I needed to create a gatsby-node.js. Do you have an example for this as well? My problem is, that the result on the ssr generated page from the markdown content does not match the client-side version. When you open a page directly the css is not correct (eg. material-ui elements completely messed up), only as soon as you navigate from one to another page it looks the way it is planned... I ask you, because the example you linked to does not use markdown files... :/ |
@natterstefan I'm not a gatsby expert, just spent a day trying to understand and figure out this one issue for a teammate. Therefore I can't really offer much advice outside of this particular problem I was trying to solve. I did notice you were using gatsby 2.0 beta? Maybe that's an issue? Maybe the plugin system is different enough that my fix won't apply there? |
Thanks @pdhodgkinson, yeah I am not an expert either. So you are not using gatsby 2.0 beta (yeah I do, thought what could go wrong ^^). Trying to downgrade and build it again could be a path to follow. Let's see, thank you. |
I'm also seeing the FOUC when loading a small page and some fonts. Looks gnarly. It only happens when I load a page from |
@markthomasmiller your site is only using CSS module's? Is it open source? |
Hey @markthomasmiller, I stumbled upon this comment from @cpboyd a few days ago and finally resolved it. The important learnings for me were (using Gatsby 2.0):
You can read more about it here in the official migration guide.
I needed to add them as well to make it work. Additionally, I had to not remove the SSR css styling in the client. But this could probably be solved by trying another solution proposed by @cpboyd:
Right now I have not tested this but I will. You can find my current project with the tips applied from above here: https://github.com/natterstefan/react-trello-multiboard-page. |
Turn out I forgot to add |
@pdhodgkinson that fixed my issue, thank you! I was able to apply withRoot on my layouts only so that I don't have to apply it to each pages. |
I am having a similar FOUC problem with Gatsby 2 and Material UI. my gatsby-srr.js file is similar to @pdhodgkinson recommendation const React = require('react')
const { renderToString } = require('react-dom/server')
const JssProvider = require('react-jss/lib/JssProvider').default
const getPageContext = require('./src/getPageContext').default
function replaceRenderer({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
}) {
// Get the context of the page to collect side effects
const muiPageContext = getPageContext()
const bodyHTML = renderToString(
<JssProvider registry={muiPageContext.sheetsRegistry}>
{bodyComponent}
</JssProvider>
)
replaceBodyHTMLString(bodyHTML)
setHeadComponents([
<style
type="text/css"
id="jss-server-side"
key="jss-server-side"
dangerouslySetInnerHTML={{
__html: muiPageContext.sheetsRegistry.toString(),
}}
/>,
])
}
exports.replaceRenderer = replaceRenderer in development, I don't have any FOUC problem only when I build and serve the production files. I have tried to play a bit with the options of the Workbox but without any major success in removing this FOUC effect unless disabling it. Not sure if this can help finding a complete solution to this FOUC issue Thanks |
I'm in desperate need of some help! I've been so many hours around this flickering issue and honestly not sure what else to do... On development it works fine but once I build and serve either locally or on Surge or Netlify it just looks so bad. here it's a preview: I'm using Emotion and bootstrap css, here it's my repo: I was thinking maybe to implement something like @KyleAMathews thanks for this great stuff, I'm in love with Gatsby |
Update: Fixed this with adding gatsby-plugin-emotion to gatsby-config, as an object with an empty options property, as in the example on the gatsby-plugin-emotion page. Wanted to chime in with the same issue as described here, especially as @Orlandohub. The repo is not public, but the site I'm working on (beta.mathematic.org) is using gatsby v2, emotion and bootstrap for css, and it is getting a FOUC. The site is pretty light so its not that long lasting, but it's pretty unfortunate. If anybody has any idea why this is, that would be very appreciated be cause this is a blemish on an otherwise amazing suite of technologies. |
@orshick can you please tell me how are you importing the bootstrap css? More precisely, on what component, |
@Orlandohub I doubt this is due to css not loading fast enough, as the problem occurs also on fresh project made with gatsby starter and gatsby-plugin-sass. Altough I am suspecting that it could be happening only when building develop |
@Orlandohub For bootstrap I just installed it into my node modules (this is bootstrap 4 I'm talking about here), and imported only the parts of the css that I wanted in my layout file like so: import 'bootstrap/dist/css/bootstrap-grid.min.css'
import 'bootstrap/dist/css/bootstrap-reboot.min.css' You're right, looking at your repo you did do exactly as I did, so unfortunately I'm out of ideas for what the issue on your site could be. |
@orshick Thanks for the details, I managed to solve the issue by changing the way I was implementing my code. @ljaniszewski you're right, it's not due to the fact of css not loading fast enough. |
@Orlandohub even then its not a guarantee, i had a simple landing page for a project that had a handful of small pieces of text, literally only 4 PNGs, and only two fonts. Still couldn't get the FOUC to go away. I don't have this same issue with Nuxt at all. |
@Orlandohub i was about to address the issue you had. I've been digging through your code and it was actually implementation issue than actually one with css. I fiddled with it and managed to get it to resolve the issue you had. But glad you figured it out |
I resolved that problem, when i had got rid of styled components and replaced them with gatsby sass. |
@tetreault in your case all I can say it's if you're using |
In what way was your code doing "conditional rendering"? I have a generic My experienceOne bug I'm observing is Bootstrap styles not being applied properly on initial page load. When I refresh, they are properly applied. The way I'm importing Bootstrap (3.3.7) is with @import '~bootstrap/dist/css/bootstrap.min.css'; at the top of my scss file. What I'm SeeingInitial Load (styles look bad)When I first open my app in a new incognito session, I see the bootstrap styles in a After refreshing (styles look good)When I refresh the page, it seems like the service worker has converted the The other difference is Bootstrap appears after my app: <link as="script" rel="preload" href="/app-1a423a0e7e769206d760.js">
<link rel="stylesheet" type="text/css" href="/0.a37c6b632759115bdcf1.css"> Possible LeadsStyle ordering bug in Gatsby#8092 feels particularly relevant. Per this comment:
Properly configuring gatsby-plugin-sassMaybe I have to properly configure Updates
|
@kevinmichaelchen have a look at this https://spectrum.chat/?t=7b865415-01c3-40e7-8a3b-7966756f6cf4 I think it might help you |
@Orlandohub Thanks. I fixed my issue here. It seems mildly related to react-sizes, but I still can't figure out why. |
struggling with this using emotion https://gatsby-casper.netlify.com/ The transition on the cards really exacerbates the issue. repo: https://github.com/scttcper/gatsby-casper |
@scttcper That really don't looks like a Gatsby nor a Emotion issue. You think about the wiggling of the text during the transition of the cards on hover? Looks to me as a common thing in CSS. You can try |
@tujoworker i'm getting a much larger flash of unstyled content on initial load that doesn't happen w/ the development server. Here is a gif with internet throttled in chrome. Edit: ours was fixed by @geocine in scttcper/gatsby-casper#26 there was changes in the gatsby emotion plugin we weren't following correctly |
Using styled components and following the docs fixed the issue for me: https://www.gatsbyjs.org/docs/debugging-replace-renderer-api/#fixing-the-replacerenderer-error |
Sorry to add to the noise, but I'm also experiencing a rather unpleasant FOUC with Gatsby and styled-components (using |
@lucasjohnston did you check if any of your plugins might be conflicting because they are using the same |
@protoEvangelion Yup - I'm not touching |
I've just merged in the redesign (with the FOUC), you should see the error I'm encountering - https://github.com/monzo/progression-framework. I've also attached the Chrome Performance view. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Regarding Material-UI, we are taking care of the problem in #8237 (comment). |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m Thanks again for being part of the Gatsby community! |
Hi all, [MY SOLUTION] Installed and configured plugins as documented on https://www.gatsbyjs.org/docs/styled-components/ [THE ISSUE] Migrated from CSS Modules to Styled Components and forgot to install and configure the corresponding plugins properly. Hope this helps someone out there as this caused me a few days of annoyance. |
I was experiencing the same issue with a Gatsby site hosted on Netlify using gatsby-plugin-web-font-loader - using typefaces and hosting fonts locally solved the problem for me. |
With self-hosted fonts, I was getting consistent FOUT on my build. (On Netlify, but also when simulating the build locally). A peek at the network tab showed that they were being loaded much later than many of the initial requests. A switch to simply loading them by importing a CSS file in my Layout component's module got them loading much sooner. |
They weren't? Did you mean they were? |
🤦🏼♂️Yup, were. I updated my comment. 🥴 |
This worked for me too! even with a sass file! Now I have this in one of my JS files:
|
A bit random, but I ran into this issue, and I fixed it by deleting old pages in my |
Summary
I have a gnarly flash of unstyled content when I load my page from a
gatsby build
. I can replicate it in both brower-sync locally and with my AWS bucket that I use to host it on my company intranet.Relevant information
I am using Material UI V1 components. I tried this plugin that was suggested in this thread but like... It doesn't solve my problem.
Gatsby Develop doesn't show the problem because of the way it builds, I guess.
I had a look at my dev tools network tab and saw that
component-src-layouts
is loading slightly slower than mycomponent-src-page
, so the page content is loading before the layout or something?So I'm thinking that if I block
component-src-layouts
, I never get my CSS and it remains 'unstyled'... is there a way to load this component first? That might be the trick here.Environment (if relevant)
File contents (if changed)
gatsby-config.js
:package.json
: N/Agatsby-node.js
:gatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: