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
Code Splitting and SSR styles #118
Comments
Can you share how you load your styles? Is is plain css, styled components or something else? |
Ah, it’s the example code? You don’t load any other styles? |
Yeah the example code, no other styles was added. Thanks for your help 😄 |
This is a razzle problem i think. However, I don't have a great answer for you. Open to PR's though. |
@alexandcote Hmm, is it possible these issues are related? #120 On the server, while material-ui does put out class names on elements, it does not output styles in the header. I get the same unstyled to styled flicker when reloading the page. EDIT: Ignore me, the issue still exists without async component, so it's a material-ui issue. |
@krazyjakee you can try to remove the lazy loading on the home component. From
To
Let me know if it resolve your problem |
@alexandcote sorry, I didn't think to test this first. It did not resolve the problem so it's not the same issue. |
In After.js here, is this only client side rendered? If you disable javascript you can see that it renders the Home component contents but only the initial client css that is imported in |
Tested in Razzle with javascript disabled and page loads with styles as expected so might be an After.js problem? |
@garmeeh I think it's a problem with |
@alexandcote This is actually a "problem" with webpack, where css chunks are not handled well when imported from a module that is imported with a dynamic Might actually be a good idea if after.js would use this by default. After all, code splitting and SSR is the point here. I'll look into it. But, you could also just go around that problem and use one of the many css-in-js™ solution at your disposal! I highly suggest JSS. |
I tested with JSS like @Madumo suggest and it worked perfectly ! Thanks again 😄 |
@Madumo makes sense alright. I think this is a Razzle issue rather than after.js since it's building the server etc. I do think it would be great to have this by default. Currently using |
This is a Razzle issue. However, with latest alpha's of razzle, we use mini-css-extract. Let's move this issue over there. |
This still seems to be an issue purely with the lazy loading of a component. As @alexandcote states When you make the component not lazy load you do not get the FOUC. I've noticed with the other Razzle examples the CSS file is including on the SSR side, so its definitly the lazy loading side of things associated with After.js additionally when the lazy load kicks in the css file is not outputted to the assets.json to be included. Any ideas? |
It is actually not related to App.js import './App.css'
import './tailwind.css'
import React from 'react'
import Route from 'react-router-dom/Route'
import Switch from 'react-router-dom/Switch'
import Loadable from 'react-loadable'
const Home = Loadable({
loader: () => import('./Home'),
loading: () => null,
})
const App = () => (
<Switch>
<Route exact path="/" component={Home} />
</Switch>
) when I run build command result (please note, two
assets.json {
"client": {
"css": "/static/css/bundle.cf147a1e.css", // -- main --
"js": "/static/js/bundle.a50ceeae.js"
}
} So flash will be noticed in production mode as second Html <html lang="">
<head>
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta charSet='utf-8' />
<title>Welcome to Razzle</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/bundle.5c3433c4.css"> <!-- main only -->
</head>
-----------
-----------
</html> Solution |
@SheikhG1900 hey man can you please tell me how you got the other styles in the chunks ? |
It seems like this was never resolved. I'm still seeing the flash behavior described by the OP. I'm using a vanilla install of afterjs, ran the production build and served it and I'm still seeing the flash. |
@heshamelmasry77 please check this code |
It's bit ugly but I got to manage to work it with At least, for style perspective, after.js should provide some way to inject additional header after in |
We had very strange issues with certain classes not matching up on initial client render. The fix was to use only react-dom/render in production but for development, only use hydrate after the initial mount. I may still have a misunderstanding of how everything works but this fixed it for us. We have a very specific setup so this is pseudo code. client.js import React from 'react';
import { render, hydrate } from 'react-dom';
import { ensureReady } from '@jaredpalmer/after';
import After from '@jaredpalmer/after/After';
import routes from './routes';
ensureReady(routes).then(data => {
let renderMethod = render;
if (window.NODE_ENV === 'development') {
renderMethod = module.hot ? render : hydrate;
}
renderMethod(
<After data={data} routes={routes} />,
document.getElementById('root'),
() => {
const jssStyles = document.getElementById('jss-ssr');
if (jssStyles && jssStyles.parentNode) {
jssStyles.parentNode.removeChild(jssStyles);
}
}
);
});
if (module.hot) {
module.hot.accept();
} |
From what I research, you may suffer for FOUC because your main css bundle does not include all the necessary styles (because your css is spit among entry). Digging into the code, it is marked as @todo https://github.com/jaredpalmer/razzle/blob/43160eb1cdbbe5b4353a714a3db7faba629a1bd3/packages/razzle/config/createConfig.js#L555 You can combine all css into 1 file inside your
You also need to change your html accordingly |
@SheikhG1900 Is it possible to handle css chunks with asyncComponent from after.js? I tried to do it follow by instructions with react-loadable, but in this case method |
it's too late I know, but we fixed this in #232 and it's going to get merged soon. |
First of all, you are genius ! Thanks for all your libs 🙏
I tested this lib during the weekend and it worked like a charm, I love the approach you propose. I'm wondering If you already had issue with brief flash of unstyled content. I found two other closed issues #104 and jaredpalmer/razzle#307 but I think the issue still there with code splitting.
I made some tests and here the result:
Note here that both app run in production mode.
Lazy loaded Home component
No lazy loaded
Any idea how can I fix this and keep the code splitting 💅
Thanks a lot again for your time and work 🥇
The text was updated successfully, but these errors were encountered: