🎨 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
Johan Girod 2021-05-17 16:29:32 +02:00
parent 7fde5bf8c1
commit 8fec6395f1
2 changed files with 16 additions and 1 deletions

View File

@ -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>

View File

@ -21,6 +21,7 @@ const prerenderConfig = () => ({
staticDir: path.resolve('dist'),
renderer: new Renderer({
renderAfterTime: 5000,
inject: true,
skipThirdPartyRequests: true,
}),
postProcess: (context) => {