CSS content-visibility for React devs

Hey, it’s Seb from This Week In React here đź‘‹

For your information, with Safari 18 release, CSS content-visibility is now available in all browsers, and I think React developers should care.

I wanted to share the news in my newsletter, but the info…


This content originally appeared on DEV Community and was authored by Sebastien Lorber

Hey, it's Seb from This Week In React here đź‘‹

For your information, with Safari 18 release, CSS content-visibility is now available in all browsers, and I think React developers should care.

Image description

I wanted to share the news in my newsletter, but the information is spread over Twitter, so I thought I'd aggregate the relevant bits here to make it more convenient to understand. It's not going to be a deep dive, I'm just sharing interesting references you might like.

Let's start with the MDN description:

It enables the user agent to skip an element's rendering work (including layout and painting) until it is needed — which makes the initial page load much faster.

TLDR: you can improve your page rendering performance (including Lighthouse score and SEO) with this new CSS rule, in particular with the content-visibility: auto; value on pages containing large lists.

It can be a good middle ground between bad rendering performance, and a React virtualization library, as long as you are able to approximately estimate the size of the list items.

.large-list-item {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

Malte Ubl (CTO of Vercel) also explained this on Twitter:

Image description

Image description

Vercel already uses it in production, giving some example use cases:

Image description

If you want a more concrete optimization case study, there's also this article from Nolan Lawson explaining how he optimized a slow emoji picker with content-visibility. Unfortunately, it doesn't seem to work immediately on <img loading="lazy"> tags.

Image description

Bonus: you improve the accessibility of your app compared to most virtualization solutions: you can ctrl+f and search for content that would otherwise not be in the DOM.

Even if it's not widely supported yet, it can be adopted today as a progressive enhancement.

See also this web.dev article.

Don't forget to subscribe to This Week In React for more news like this.


This content originally appeared on DEV Community and was authored by Sebastien Lorber


Print Share Comment Cite Upload Translate Updates
APA

Sebastien Lorber | Sciencx (2024-09-25T09:46:27+00:00) CSS content-visibility for React devs. Retrieved from https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/

MLA
" » CSS content-visibility for React devs." Sebastien Lorber | Sciencx - Wednesday September 25, 2024, https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/
HARVARD
Sebastien Lorber | Sciencx Wednesday September 25, 2024 » CSS content-visibility for React devs., viewed ,<https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/>
VANCOUVER
Sebastien Lorber | Sciencx - » CSS content-visibility for React devs. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/
CHICAGO
" » CSS content-visibility for React devs." Sebastien Lorber | Sciencx - Accessed . https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/
IEEE
" » CSS content-visibility for React devs." Sebastien Lorber | Sciencx [Online]. Available: https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/. [Accessed: ]
rf:citation
» CSS content-visibility for React devs | Sebastien Lorber | Sciencx | https://www.scien.cx/2024/09/25/css-content-visibility-for-react-devs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.