🎨 Fix le prérendu avec styled-component
Jusqu'alors les styled-component n'étaient pas pris en compte dans le prérendu, ce qui aboutissait à un CLS très important sur nos pages. C'est maintenant réparépull/1570/head
parent
7fde5bf8c1
commit
8fec6395f1
|
@ -208,7 +208,21 @@
|
|||
var b = document.documentElement
|
||||
b.setAttribute('data-useragent', navigator.userAgent)
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Hack to force styled components to render styles during prerender
|
||||
if (window.__PRERENDER_INJECTED) {
|
||||
window.onload = () => {
|
||||
var el = document.createElement('style');
|
||||
document.head.appendChild(el)
|
||||
var styles = document.querySelectorAll('style[data-styled]')
|
||||
for (style of styles.values()) {
|
||||
for (rule of style.sheet.rules) {
|
||||
el.appendChild(document.createTextNode(rule.cssText))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<!-- APP -->
|
||||
<div id="js"></div>
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ const prerenderConfig = () => ({
|
|||
staticDir: path.resolve('dist'),
|
||||
renderer: new Renderer({
|
||||
renderAfterTime: 5000,
|
||||
inject: true,
|
||||
skipThirdPartyRequests: true,
|
||||
}),
|
||||
postProcess: (context) => {
|
||||
|
|
Loading…
Reference in New Issue