opencomponents / oc-template-react

⚛️ Module for handling React templates in OC
MIT License
23 stars 16 forks source link

Render <style /> before OC react <div /> to mitigate CLS #649

Closed sforsberg closed 3 years ago

sforsberg commented 3 years ago

In an effort to mitigate Cumulative Layout Shift (CLS) for server-side rendered OCs, this change renders the<style /> tag before the OC <div /> tag to ensure the browser is able to parse the styles before rendering the OCs HTML to the DOM.

In the current project I am working on, our server-side rendered OC header is the leading contributor to our site-wide CLS issues. According to Google Search Console, our Aggregate CLS score ranges anywhere from 0.25 - 0.5+. Once this fix was implemented locally, I saw that the CLS dropped to under 0.01 in my local (typically local CLS is around 0.5 - 0.7).

Issues Fixed

kmcrawford commented 3 years ago

This LGTM, @matteofigus do you know if this will cause any issues with the render order? CLS is a big thing these days and if OC is a culprit it would be good to fix.

sforsberg commented 3 years ago

@matteofigus Can this be merged and published? 🙏

matteofigus commented 3 years ago

Released. Thanks for the help.